[英]Getting crash in Android on onResume() in my activity - Why?
The error is: 错误是:
Unable to resume activity: java.lang.NullPointerException 无法恢复活动:java.lang.NullPointerException
Here is the stack trace: 这是堆栈跟踪:
0 java.lang.RuntimeException: Unable to resume activity {com.sortitapps.movies/com.sortitapps.movies.SettingsActivity}: java.lang.NullPointerException
1 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2944)
2 at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2973)
3 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2408)
4 at android.app.ActivityThread.access$600(ActivityThread.java:165)
5 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1373)
6 at android.os.Handler.dispatchMessage(Handler.java:107)
7 at android.os.Looper.loop(Looper.java:194)
8 at android.app.ActivityThread.main(ActivityThread.java:5391)
9 at java.lang.reflect.Method.invokeNative(Native Method)
10 at java.lang.reflect.Method.invoke(Method.java:525)
11 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
12 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
13 at dalvik.system.NativeStart.main(Native Method)
14 Caused by: java.lang.NullPointerException
15 at com.sortitapps.movies.SettingsActivity.onResume(SettingsActivity.java:149)
16 at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1259)
17 at android.app.Activity.performResume(Activity.java:5200)
18 at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2931)
And here is the code. 这是代码。 Line 149 is adapter.notifyDataSetChanged();
第149行是adapter.notifyDataSetChanged(); :
:
@Override
public void onResume()
{
super.onResume(); // Always call the superclass method first
SharedPreferences settings = getSharedPreferences("prefs", 0);
int numberDesktop = settings.getInt("desktop", 0);
Log.i("Desktop purchased:", String.valueOf(numberDesktop));
int numberScans = settings.getInt("scanning", 0);
Log.i("Number of scans:", String.valueOf(numberScans));
if (settingsitems.contains("Unlock Desktop Apps") &&
numberDesktop == 2)
{
settingsitems.remove("Unlock Desktop Apps");
}
String freeapp = getResources().getString(R.string.free_app);
if (settingsitems.contains("Unlock Premium Features") &&
freeapp.equals("Yes") &&
numberScans > 10)
{
settingsitems.remove("Unlock Premium Features");
}
adapter.notifyDataSetChanged();
}
Do I need to initialize the adapter again when coming resuming? 恢复时是否需要再次初始化适配器?
Most certainly adapter is null. 最肯定的是适配器为null。
Your code doesn't show how the adapter got initialized, so it could be that it wasn't initialized with a value, or it was set to null after that. 您的代码未显示适配器的初始化方式,因此可能是未使用值初始化,或者此后将其设置为null。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.