Skip to content Skip to sidebar Skip to footer

Nullpointerexception When Setimagedrawable And Setimageresource In An Imageswitcher

I keep getting NullPointerException errors when I try to populate an ImageSwitcher with a resource. It is called using a WeakReference from within an AsyncTask, during the onPreExe

Solution 1:

You need to add views to your ImageSwitcher, either by setting a ViewFactory or calling addView twice. More info in the docs for ViewSwitcher.

For example, looking at the last stack trace in your question, the NPE happens at line 55 of ImageSwitcher.java, which is:

publicvoidsetImageDrawable(Drawable drawable)
{
    ImageViewimage= (ImageView)this.getNextView();
    image.setImageDrawable(drawable);  // <--- line 55
    showNext();
}

image is null because the views have not been set.

Post a Comment for "Nullpointerexception When Setimagedrawable And Setimageresource In An Imageswitcher"