Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loading an image throws NPE on defineTargetSizeForView when the view is not laid out / visible yet #267

Closed
deleet opened this issue May 1, 2013 · 1 comment
Labels

Comments

@deleet
Copy link

deleet commented May 1, 2013

I'm inflating views in Java code and setting the source to an image from the network:

ImageView imageView = new ImageView(img);

imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setAdjustViewBounds(true);

ImageLoader.getInstance().displayImage("http://i.imgur.com/funnycat.jpg", imageView);

Throws the exception:

05-01 10:40:39.922: E/EnumFragmentView(14167):  at com.nostra13.universalimageloader.utils.ImageSizeUtils.defineTargetSizeForView(ImageSizeUtils.java:55)
05-01 10:40:39.922: E/EnumFragmentView(14167):  at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:202)
05-01 10:40:39.922: E/EnumFragmentView(14167):  at com.nostra13.universalimageloader.core.ImageLoader.displayImage(ImageLoader.java:123)

My configuration is as follows:

final DisplayImageOptions imageOptions = new DisplayImageOptions.Builder()
        .cacheInMemory()
        .cacheOnDisc()
        .resetViewBeforeLoading()
        .build();

final ImageLoaderConfiguration imageConfig = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .defaultDisplayImageOptions(imageOptions)
        .denyCacheImageMultipleSizesInMemory()
        .discCacheSize(100 * 1024 * 1024)
        .build();

ImageLoader.getInstance().init(imageConfig);
@deleet
Copy link
Author

deleet commented May 1, 2013

Assigning a set of LayoutParams to the ImageView seems to resolve the issue:

LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(p);

@deleet deleet mentioned this issue May 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants