我观察到我的应用程序的用户发生了一些崩溃,这与配置更改和重新创建的 Activity 有关,但我无法重现它。这个问题似乎出在 Android 类内部,因此我没有机会直接修复它。
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)
由于我无法重新创建它,因此在 Goggle issuestracker 上打开错误报告将毫无用处。有人知道这里发生了什么吗?有人遇到过这种情况吗?
显然存在一个错误,因为 ActivityThread#createNewConfigAndUpdateIfNotNull(Configuration, Configuration)
方法负责将 null
值传递给 Configuration#setTo( Configuration)
的第一个参数注释为 @NonNull
。
崩溃主要发生在 Android 7.1.1 上,该应用程序针对 SDK 28。
最佳答案
此问题仅发生在 Android 7.0 及更高版本中...当应用程序使用夜间模式创建且屏幕旋转(配置更改)时,这可能是 DayNight 主题中的错误。
关于java - 由于 NPE 恢复 Activity 时发生崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57026240/