-2

我有警报对话框,如果我按是,它将转到其他活动

这是我的代码

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

请帮助我..错误是什么?以及如何解决?

我已经坚持并强调要完成这个程序..

4

1 回答 1

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

问题在于 TaskActivity . Not inDialogActivity . You are passingnull` 作为输入并试图将其解析为整数。

TaskActivity.java 第 49 行是有问题的行。

于 2012-11-20T15:54:13.310 回答