Search code examples
androidimageimageviewclasscastexceptionandroid-ion

ion java.lang.ClassCastException


I'm using ION (https://github.com/koush/ion) to load images from the web into a ListView of ImageView. Currently I want to get the bitmap from the ImageView, but I'm getting one exception that is force closing my app:

java.lang.ClassCastException: com.koushikdutta.ion.IonDrawable cannot be cast to android.graphics.drawable.BitmapDrawable

These are the lines that I'm using:

final ImageView itemImageView = (ImageView)view.findViewById(R.id.photoImage);
final Bitmap itemDrawable = ((BitmapDrawable) itemImageView.getDrawable()).getBitmap();

How can I solve this? Thanks in advance!


Solution

  • It may be worth looking into:

    nostra13's "Universal Image Loader"

    It's an awesome library with tons of features to display images from URLs, cast to bitmaps, etc.