Crash when resuming Activity due to NPE
Asked Answered
Q

3

10

I've observed some crashes among the users of my app which is related to a configuration change and the Activity being recreated, I was not able to reproduce it. The issue seems to be inside the Android classes and therefore there's no chance for me to fix it directly.

Fatal Exception: java.lang.NullPointerException: Attempt to read from field 'float android.content.res.Configuration.fontScale' on a null object reference
       at android.content.res.Configuration.setTo + 904(Configuration.java:904)
       at android.content.res.Configuration.(Configuration.java:891)
       at android.app.ActivityThread.createNewConfigAndUpdateIfNotNull + 5133(ActivityThread.java:5133)
       at android.app.ActivityThread.performConfigurationChanged + 5203(ActivityThread.java:5203)
       at android.app.ActivityThread.performConfigurationChangedForActivity + 5117(ActivityThread.java:5117)
       at android.app.ActivityThread.handleResumeActivity + 3994(ActivityThread.java:3994)
       at android.app.ActivityThread.handleLaunchActivity + 3070(ActivityThread.java:3070)
       at android.app.ActivityThread.handleRelaunchActivity + 5006(ActivityThread.java:5006)
       at android.app.ActivityThread.-wrap21(ActivityThread.java)
       at android.app.ActivityThread$H.handleMessage + 1665(ActivityThread.java:1665)
       at android.os.Handler.dispatchMessage + 102(Handler.java:102)
       at android.os.Looper.loop + 154(Looper.java:154)
       at android.app.ActivityThread.main + 6816(ActivityThread.java:6816)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run + 1563(ZygoteInit.java:1563)
       at com.android.internal.os.ZygoteInit.main + 1451(ZygoteInit.java:1451)

Since I'm not able to recreate it, opening a bug report on Goggle issuetracker would be pretty useless. Does anyone have a clue on what's happening here? Has anyone encountered this before?

There is clearly a bug because the ActivityThread#createNewConfigAndUpdateIfNotNull(Configuration, Configuration) method, which is responsible for passing a null value to Configuration#setTo(Configuration) has its first parameter annotated as @NonNull.

The crashed happened mainly on Android 7.1.1, the app targets SDK 28.

Quota answered 14/7, 2019 at 9:46 Comment(4)
are you using custom fonts by chance ?Fanfani
@Fanfani nopeQuota
Were you able to figure out why this happens? It happens to me on Android 7.0 when I change the orientation in MainActivity. No issues with Android 5.1.1. Also, it only happens when the app is in night mode upon creation. github.com/kebiro/TriviaQuizOverkill
@Overkill No, I did not manage to solve it.Quota
B
4

This issue is only happening with android version 7.0 and above...when the app is created with night mode and the screen rotated(configuration change) ,it could be a bug in the DayNight Theme.

Brainy answered 26/11, 2019 at 14:58 Comment(0)
F
2

I have this issue too on android 7.1 but i find out my activity created twice because setTheme(R.style.custom_style) called after super.onCreate(savedInstanceState) when fix this issue crash not happened anymore on configuration changes

hope this help

Floatable answered 6/10, 2019 at 14:56 Comment(0)
I
1

I did a lot of research on this problem and I noticed that this problem only occurs in Android 7 and in the DayNight theme. To solve this problem, you can not use the DayNight theme in Android 7, such as the following code:

 if (Build.VERSION.SDK_INT==Build.VERSION_CODES.N||Build.VERSION.SDK_INT==Build.VERSION_CODES.N_MR1){
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        }

My problem was solved by adding the above code I hope this solution has been helpful.

Inadvertence answered 11/5, 2020 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.