Android Adapter getView() Returns NullPointer Inflate Error Exception When Using measure()

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.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

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