9

In the "Crashes and ANRs" of the Google Play Developer console I've got such a 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)

The device that has this problem is Galaxy S4 and runs Android 5.0

What it can be - there is not a single line from my code, why does it fail?

Thanks a lot!

6
  • But your app runs normally on your device/the devices of most of your users? Commented Jul 15, 2015 at 19:22
  • Yes. But I've deployed it to production recently, so there is not much statistics. Commented Jul 15, 2015 at 19:23
  • Just to make sure - You've tested it on 5.0, right? Commented Jul 15, 2015 at 19:24
  • Yes. It goes all right on several known 5.0 devices Commented Jul 15, 2015 at 19:26
  • 2
    I experienced this too, and this happened quite often. getAssets() is not from our code, it is from OS's code. Most likely it is this bug: code.google.com/p/android/issues/detail?id=56296. Star that in order to get more attention. Commented Nov 3, 2015 at 2:46

3 Answers 3

4

I've got this in my console too. It seems this occurs when users start the app when it's currently being updated or just after that.

A possible workaround would be to check if getResources returns null when the application start, and kill it if it does:

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

Sign up to request clarification or add additional context in comments.

Comments

1

Make sure that anywhere you call getAssets(), you call it as:

getApplicationContext().getAssets()

It would appear as if you are calling getAssets() in a class that does not have the application context available, hence the fact that it is null.

1 Comment

Thanks for your suggestion but I don't call to getAssets() anywhere. By the way - assets folder of my app is empty.
0

I've got the same exception while added the below overlay in the AndroidManifest.xml file. Even after removing the Overlay code, landed into the above exception.

<overlay android:targetPackage="com.android.systemui"
             android:priority="1"/>

Just close the Android Studio completely. Open the project again. Clean and Build the exception got cleared.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.