6

如果我通过单击主页将我的应用程序置于后台。

然后转到系统设置->显示->字体大小->并从(普通)更改为(巨大)

然后去点击我的应用程序把它放回前台

我收到以下错误消息:

FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity{ActivityThread.java)

有谁知道可能导致此错误的原因?

这是与该错误有关的整个 Logcat:

    08-01 14:16:44.555: E/AndroidRuntime(3979): FATAL EXCEPTION: main
    08-01 14:16:44.555: E/AndroidRuntime(3979): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.MainActivity}: java.lang.NullPointerException
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3576)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.access$800(ActivityThread.java:140)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.os.Handler.dispatchMessage(Handler.java:99)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.os.Looper.loop(Looper.java:137)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.main(ActivityThread.java:4921)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at java.lang.reflect.Method.invokeNative(Native Method)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at java.lang.reflect.Method.invoke(Method.java:511)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at dalvik.system.NativeStart.main(Native Method)
    08-01 14:16:44.555: E/AndroidRuntime(3979): Caused by: java.lang.NullPointerException
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.Menu.ResetMenuPosition(Menu.java:2328)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.Menu.onActivityCreated(Menu.java:573)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:891)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1810)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:501)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at com.myapp.MainActivity.onStart(MainActivity.java:299)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.Activity.performStart(Activity.java:5198)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2083)
    08-01 14:16:44.555: E/AndroidRuntime(3979):     ... 12 more
4

1 回答 1

2

在 Xamarin 中,将这些代码行添加到您的活动顶部。

[Activity(ConfigurationChanges =ConfigChanges.FontScale)]
public class ExampleActivity : AppCompatActivity { rest of the code ... }
于 2018-04-05T08:09:30.803 回答