Okay, so you decide to use the measure() method of the View class in order to get the Adapter item view’s width and height.

In Lollipop devices, it works but when you deploy it some other device or emulator on pre-Lollipop devices, it gives out a NullPointerException when inflating.

This error message is very confusing as it does not pinpoint you to the exact problem in the XML file. The problem though, is not within the XML file layout.

This occurs when your layout is a RelativeLayout and the reason for this is that Inflater does not extract layout_width and layout_height attributes when you do not assign its parent as an argument in the inflate method.

The solution to this problem is to call setLayoutParams() with the specified width and height and then call measure().

That should fix it. Even a width and height of 0 will do the trick.

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.

Here is a useful method to convert a hexadecimal to binary using Java. If you may wonder why the HEX_String object contains 0 to 9 and A to F, it is because a hexadecimal or base-16 notation uses 16 different digits: 0 up to 9 and then the letters A, B, C, D, E, F to represent 10, 11, 12, 13, 14 and 15.

Related Posts Plugin for WordPress, Blogger...