21

I am getting a crash on Android Lolipop.

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence android.content.res.StringBlock.get(int)' on a null object reference   
at android.content.res.AssetManager.getResourceValue(AssetManager.java:213) 
at android.content.res.Resources.getValue(Resources.java:1334)  
at android.content.res.Resources.getValue(Resources.java:1323)  
at android.content.res.Resources.loadXmlResourceParser(Resources.java:2796) 
at android.content.res.Resources.getLayout(Resources.java:1143) 
at android.view.LayoutInflater.inflate(LayoutInflater.java:412)

Generally happens while inflating a view. Any suggestions why it happens on Lollipop only ?

Floern
  • 33,559
  • 24
  • 104
  • 119
Gaurav
  • 667
  • 2
  • 13
  • 28
  • 7
    Excuse me, but this is not a duplicate just because the exception is `NullPointerException`. This is a crash happening only in a specific Android version, with a stack trace mentioning only framework classes, therefore a developer cannot simply check for a null variable. Any possible workaround provided in an answer would be specific to this case, and not in `NullPointerException` crashes in general. – Giorgos Kylafas Mar 30 '16 at 09:18
  • I'm also getting this type of crash in lollipop. – Mani Aug 29 '16 at 08:57
  • Can you post the layout xml file which is causing this error? – bluefalcon Sep 12 '16 at 05:36
  • give the code, as 99% u not initialize something and then NPE – Rodriquez Sep 12 '16 at 06:05

2 Answers2

7

It is may be because of an attribute is null.

For example android:foreground="?android:attr/selectableItemBackground" may be null, try to use android:foreground="?attr/selectableItemBackground".

0

In my case it occurred when I was setting a image to notification from service . I remove the relevant code and it started working fine

Manohar
  • 22,116
  • 9
  • 108
  • 144