سؤال

I have 2 pages and all I want is if user click button at the first page ,it will show ProgressDialog and go to second page , and if user click back button to resume to the first page it won't show ProgressDialog so I try

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();
}

but it forceclose

05-09 10:02:54.520: ERROR/AndroidRuntime(623): FATAL EXCEPTION: main

05-09 10:02:54.520: ERROR/AndroidRuntime(623): java.lang.RuntimeException: Unable to resume activity {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: ERROR/AndroidRuntime(623): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2684) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at android.os.Handler.dispatchMessage(Handler.java:99) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at 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: ERROR/AndroidRuntime(623): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 05-09 10:02:54.520: ERROR/AndroidRuntime(623): at 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: ERROR/AndroidRuntime(623): Caused by: java.lang.NullPointerException 05-09 10:02:54.520: ERROR/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: ERROR/AndroidRuntime(623): at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3118)

please help

لا يوجد حل صحيح

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top