小编Dic*_*ong的帖子

Android - 自定义对话框在定义多个按钮时抛出NullPointerException

这是定义我的自定义对话框的代码.当我显示此对话框时,它会在注释行中抛出NullPointerException.

    protected Dialog onCreateDialog (int id) {
    Dialog dialog = null;
        switch (id) {
        case DIALOG_SUCCESS_ID:

            Context thisContext = this;

            dialog = new Dialog(thisContext);

            dialog.setContentView(R.layout.win_dialog);
            dialog.setTitle("Stage One");

            TextView timeScore = (TextView) dialog.findViewById(R.id.TimeScore);
            timeScore.setText (elapsedTimeSec + "s");
            TextView bestScore = (TextView) dialog.findViewById(R.id.BestScore);
            bestScore.setText ("Best Score: (n/a)");

            Button retry = (Button) dialog.findViewById(R.id.Retry);
            retry.setOnClickListener(new View.OnClickListener() {
                public void onClick (View v) {
                    Intent retry = new Intent(v.getContext(), LevelOne.class);
                    startActivityForResult(retry, 0);
                    finish();
                }
            });

            Button menu = (Button) dialog.findViewById (R.id.ReturnToMenu);

            //Throws NullPointerException at this …
Run Code Online (Sandbox Code Playgroud)

java mobile android exception nullpointerexception

1
推荐指数
1
解决办法
2060
查看次数

标签 统计

android ×1

exception ×1

java ×1

mobile ×1

nullpointerexception ×1