gpt4 book ai didi

Android:如果更改系统字体大小,应用程序会崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:16:18 25 4
gpt4 key购买 nike

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

然后转到系统设置 -> 显示 -> 字体大小 -> 并将(正常)更改为(大)

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

我收到以下错误消息:

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

最佳答案

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

[Activity(ConfigurationChanges =ConfigChanges.FontScale)]
public class ExampleActivity : AppCompatActivity { rest of the code ... }

关于Android:如果更改系统字体大小,应用程序会崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18001517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com