我有 2 页,我想要的只是如果用户在第一页单击按钮,它将显示 ProgressDialog 并转到第二页,如果用户单击返回按钮以恢复到第一页,它不会显示 ProgressDialog 所以我尝试
Btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dialog = ProgressDialog.show(MainActivity.this, "",
"Loading. Please wait...", true);
dialog.setMax(2);
Intent statPage = new Intent(MainActivity.this, Statistic.class);
startActivity(statPage);
}
});
public void onResume() {
if (dialog.isShowing()) {
dialog.dismiss();
}
super.onResume();
}
但它强制关闭
05-09 10:02:54.520: ERROR/AndroidRuntime(623): FATAL EXCEPTION: main
05-09 10:02:54.520: 错误/AndroidRuntime(623): java.lang.RuntimeException: 无法恢复活动 {android.test.cal/android.test.cal.MainActivity}: java.lang.NullPointerException 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3128) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app.ActivityThread .handleResumeActivity(ActivityThread.java:3143) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.ActivityThread.access$2300(ActivityThread.java:125) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.ActivityThread$H.handleMessage(ActivityThread .java:2033) 05-09 10:02:54.520: 错误/AndroidRuntime(623):在 android.os.Handler.dispatchMessage(Handler.java:99) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.os.Looper.loop(Looper.java:123) 05-09 10 :02:54.520: ERROR/AndroidRuntime(623): at android.app.ActivityThread.main(ActivityThread.java:4627) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at java.lang.reflect。 Method.invokeNative(Native Method) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at java.lang.reflect.Method.invoke(Method.java:521) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 com.android.internal。 os.ZygoteInit.main(ZygoteInit.java:626) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at dalvik.system.NativeStart.main(Native Method) 05-09 10:02:54.520:错误/AndroidRuntime(623): 由: java.lang.NullPointerException 05-09 10:02:54.520: 错误/AndroidRuntime(623): at android.test.cal.MainActivity.onResume(MainActivity.java:165) 05- 09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1149) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app. Activity.performResume(Activity.java:3823) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)1149) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.Activity.performResume(Activity.java:3823) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)1149) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在 android.app.Activity.performResume(Activity.java:3823) 05-09 10:02:54.520: 错误/AndroidRuntime(623): 在android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)
请帮忙