Saiful Islam Sajib
Saiful Islam Sajib

Reputation: 2411

How do I programmatically check whether an image (PNG, JPEG) is corrupted or unsupported in android?

I am trying to load image in imageview but for some image my app is crashing while i am trying to get bitmap from image path.

Here is my code:

public Bitmap getBitmap(String imagePath){
    Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
    return bitmap;
}

Log:

   Process: kgs.com.librarytest2, PID: 17587
   java.lang.NoClassDefFoundError: Failed resolution of: 
   Ljavax/imageio/ImageIO;
   at it.lamba.utils.KImageCheck.analyzeImage(KImageCheck.kt:26)
   at it.lamba.utils.KImageCheck.getImageData(KImageCheck.kt:53)
   at com.kitegamesstudio.kgspicker.ui.PickerFragment.handleSelection(PickerFragment.kt:524)at com.kitegamesstudio.kgspicker.ui.PickerFragment$getPagerAdapter$selectionDe legate$1.onItemSelected(PickerFragment.kt:494) at com.kitegamesstudio.kgspicker.ui.PagerFragment$selectionDelegate$1.onItemS lected(PagerFragment.kt:35) at com.kitegamesstudio.kgspicker.ui.RecyclerViewAdapter$ImageItemVieHolder$bi d$$inlined$with$lambda$1.onClick(RecyclerViewAdapter.kt:125) at android.view.View.performClick(View.java:6392)

Upvotes: 2

Views: 911

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

Note that your code (a getBitmap() method) is unrelated to your stack trace, which does not refer to this method.

You appear to be using this library. It is designed for use with Java SE, on a desktop or a server. It is using javax.imageio.ImageIO, which is not part of the Android SDK. You will need to remove this library from your project.

Upvotes: 1

Related Questions