Exception in Android code at application launch

In the "Failures and ANRs" of the Google Play Developer Console, I have this report:

java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.AssetManager android.content.res.Resources.getAssets()' on a null object reference at android.app.LoadedApk.getAssets(LoadedApk.java:590) at android.app.LoadedApk.makeApplication(LoadedApk.java:646) at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5088) at android.app.ActivityThread.access$1600(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1509) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5944) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1389) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1184) 

A device that has this problem is the Galaxy S4 and is running Android 5.0

What could it be - there is not a single line from my code , why is this failing?

Many thanks!

+5
source share
2 answers

Make sure you call getAssets() , you name it like:

 getApplicationContext().getAssets() 

It would seem that you are calling getAssets() in a class that does not have an application context available, hence the fact that it is zero.

+1
source

I have it on the console too. This seems to happen when users launch the app, when it is currently being updated, or only after that.

A possible workaround would be to check if getResources returns null when the application starts, and kill it if that happens:

 public class DevToolsApplication extends Application { private static final String TAG = "DevToolsApplication"; @Override public void onCreate() { super.onCreate(); AppLogger.i(TAG, "app start..."); checkAppReplacingState(); } private void checkAppReplacingState() { if (getResources() == null) { AppLogger.w(TAG, "app is replacing...kill"); Process.killProcess(Process.myPid()); } } } 

See this for more information https://issuetracker.google.com/issues/36972466

+1
source

All Articles