gpt4 book ai didi

java - Android 应用程序在清除 RAM 内存后崩溃

转载 作者:行者123 更新时间:2023-12-02 05:47:22 25 4
gpt4 key购买 nike

我有 Android 应用程序,运行良好。但是当我尝试清理内存然后尝试打开时,它崩溃并在多个地方给出 NullPointerException 。我知道当用户清除内存时,android 会清除所有变量和共享首选项。现在我的问题是,有没有一种方法可以知道用户何时在手机设置中清除 RAM 内存。

enter image description here

这是 Logcat

05-29 15:34:19.813: E/AndroidRuntime(4932): FATAL EXCEPTION: main
05-29 15:34:19.813: E/AndroidRuntime(4932): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.softwaysolutions.rcommunication/com.softwaysolutions.rcommunication.MainActivity}: java.lang.NullPointerException
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2088)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2113)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread.access$700(ActivityThread.java:139)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1224)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.os.Handler.dispatchMessage(Handler.java:99)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.os.Looper.loop(Looper.java:137)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread.main(ActivityThread.java:4918)
05-29 15:34:19.813: E/AndroidRuntime(4932): at java.lang.reflect.Method.invokeNative(Native Method)
05-29 15:34:19.813: E/AndroidRuntime(4932): at java.lang.reflect.Method.invoke(Method.java:511)
05-29 15:34:19.813: E/AndroidRuntime(4932): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
05-29 15:34:19.813: E/AndroidRuntime(4932): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
05-29 15:34:19.813: E/AndroidRuntime(4932): at dalvik.system.NativeStart.main(Native Method)
05-29 15:34:19.813: E/AndroidRuntime(4932): Caused by: java.lang.NullPointerException
05-29 15:34:19.813: E/AndroidRuntime(4932): at com.softwaysolutions.rcommunication.NowPlayingFragment.startMyAACService(NowPlayingFragment.java:378)
05-29 15:34:19.813: E/AndroidRuntime(4932): at com.softwaysolutions.rcommunication.NowPlayingFragment.onCreateView(NowPlayingFragment.java:112)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1884)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:566)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.Activity.performStart(Activity.java:5058)
05-29 15:34:19.813: E/AndroidRuntime(4932): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
05-29 15:34:19.813: E/AndroidRuntime(4932): ... 11 more

提前致谢。

最佳答案

I've checked there and the thing is i'm trying to access a global value

您需要将所有数据保存在 onSavedInstanceState 中,并在 onRestoreInstanceState 中恢复。

关于java - Android 应用程序在清除 RAM 内存后崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23930117/

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