这是定义我的自定义对话框的代码.当我显示此对话框时,它会在注释行中抛出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)