android.view.InflateException: Binary XML File Line #: Error inflating class

This one was another pain. The error message is misleading one would think right away there is something wrong in the XML layout file.

Although there may be times the cause would be that, the most obvious cause for this is when you have large images placed in only one drawable folder.

In my case, I placed the image in the drawable-sw600dp-hdpi folder and when I deployed it in my Samsung Galaxy S2, it produced this error because Android resized the image as a Bitmap in every row in the Listview.

As well, I guess it ran out of memory since the phone only has 1GB of RAM unlike my Nexus 7 2nd Gen where it has 2GB of RAM so that masked the real cause lay on the image being resized.

The more rows shown in the ListView, the more probable occurrence that this error message will show up and crash the app.

Try to add the same images in all the drawable folders regardless if they are resized to a smaller resolution or not. At least, the Android OS will just pick up the images right away without having to resize them accordingly.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *