-2

I have a class extending ImageView. In it, I have a function that calls getDrawable().getIntrinsicWidth();. I have about 100 000 installs, and I have 10 reports of this line producing a nullpointerexception. I can't reproduce this, but would still like to fix this. For this, I need to know what throws it, but I can't test it.

Can I safely assume that getDrawable() can not throw a nullpointer exception, but returns null for some reason, so getIntrinsicWidth() throws the exception?

Also, why would it return null, unless it was set to null? I set the image only by from ShareIntents, and I filter by mimetyp "image/*". If the Uri wasn't pointing to an image, wouldn't that get sorted out during the sharing process? Or do I need to take care of that myself?

DottyPhone
  • 320
  • 1
  • 12

1 Answers1

1

Checking the java doc for ImageView.getDrawable()

/** Return the view's drawable, or null if no drawable has been
    assigned.
*/
public Drawable getDrawable() {
    if (mDrawable == mRecycleableBitmapDrawable) {
        // Consider our cached version dirty since app code now has a reference to it
        mRecycleableBitmapDrawable = null;
    }
    return mDrawable;
}

So, it can return a null pointer.

It makes sense because if you want to clear a ImageView you can call mImageView.setImageDrawable(null);

guipivoto
  • 18,327
  • 9
  • 60
  • 75