2012-11-20 49 views
-2

意圖我已經alertdialog,如果我按是它會去其他活動的Android錯誤在使用alertdialog

這是我的代碼

public class DialogActivity extends Activity { 
    final Context context = this; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_dialog); 


     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
       context); 


      alertDialogBuilder.setTitle("Your Title"); 

      alertDialogBuilder 
       .setMessage("Click yes to exit!") 
       .setCancelable(false) 
       .setPositiveButton("Yes",new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) { 

         Intent intent = new Intent(DialogActivity.this,TaskActivity.class); 
         startActivity(intent); 
        } 
        }) 
       .setNegativeButton("No",new DialogInterface.OnClickListener() { 
        public void onClick(DialogInterface dialog,int id) { 

         DialogActivity.this.finish(); 
        } 
       }); 


       AlertDialog alertDialog = alertDialogBuilder.create(); 
       alertDialog.show(); 
    } 

} 

這是我的logcat錯誤

11-15 22:01:16.882: E/AndroidRuntime(2613): FATAL EXCEPTION: main 
11-15 22:01:16.882: E/AndroidRuntime(2613): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.finaloop/com.example.finaloop.TaskActivity}: java.lang.NumberFormatException: unable to parse 'null' as integer 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread.access$1500(ActivityThread.java:117) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.os.Handler.dispatchMessage(Handler.java:99) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.os.Looper.loop(Looper.java:123) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread.main(ActivityThread.java:3683) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at java.lang.reflect.Method.invokeNative(Native Method) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at java.lang.reflect.Method.invoke(Method.java:507) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at dalvik.system.NativeStart.main(Native Method) 
11-15 22:01:16.882: E/AndroidRuntime(2613): Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at java.lang.Integer.parseInt(Integer.java:356) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at java.lang.Integer.parseInt(Integer.java:332) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at java.lang.Integer.valueOf(Integer.java:506) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at com.example.finaloop.TaskActivity.onCreate(TaskActivity.java:49) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 
11-15 22:01:16.882: E/AndroidRuntime(2613):  ... 11 more 

請幫幫我..錯誤是什麼?以及如何解決它?

我已經卡住,並強調,完成這一計劃..

+0

您發錯行爲 –

+0

例外清楚說明數字格式異常。它還指定了行號。它與警報對話或意圖無關 – Atrix1987

+0

「什麼是錯誤」?你可以閱讀堆棧嗎?它是用純英文寫成的:「無法在TaskActivity中解析'null'作爲整數」,第49行。 – njzk2

回答

2
Caused by: java.lang.NumberFormatException: unable to parse 'null' as integer 

的問題是TaskActivity . Not in DialogActivity . You are passing null`作爲輸入,並試圖解析它作爲整數。

TaskActivity.java行號49是有問題的行。

+0

thx ..我太強調解決這個問題,那麼你說我的任務活動存在問題,我忘了通過價值..感謝拯救我的生命 – user1478434