2010-06-17 5 views
1

이 AlertDialog가 충돌하는 이유를 설명 할 수 있습니까? 이것은 대단한AlertDialog 응용 프로그램이 충돌 함

package com.clicker; 

import android.app.Activity; 
import android.app.AlertDialog; 
import android.content.DialogInterface; 
import android.content.DialogInterface.OnClickListener; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 


public class Clicker extends Activity 
{ 
    public int clickerNumber = 0; 
    private TextView clickerText; 
    private Button clickerButton; 
    private Button resetButton; 

    // Called when the activity is first created. 
    @SuppressWarnings("null") 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     // Declare each of the layout objects 
     clickerText = (TextView)findViewById(R.id.clickerText); 
     clickerButton = (Button)findViewById(R.id.clickerButton); 
     resetButton = (Button)findViewById(R.id.resetButton); 

     clickerText.setText("0"); 

     final AlertDialog.Builder resetQuestion = null; 
     resetQuestion.setTitle("Reset?"); 
     resetQuestion.setMessage("Are you sure you want to reset the counter?"); 

     resetQuestion.setPositiveButton("Yes", new OnClickListener() { 
      public void onClick(DialogInterface dialog, int whichButton) { 
        clickerNumber = 0; 
        clickerText.setText("0"); 
      } 

     }); 

     resetQuestion.setNegativeButton("No", new OnClickListener() { 
      public void onClick(DialogInterface dialog, int whichButton) { 
       dialog.dismiss(); 
      } 

     }); 

     clickerButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       clickerNumber++; 
       clickerText.setText(Integer.toString(clickerNumber)); 
      } 
     }); 

     resetButton.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       resetQuestion.show(); 
      } 

     }); 
    }; 
}; 

답변

4

실패 :

final AlertDialog.Builder resetQuestion = null; 
resetQuestion.setTitle("Reset?"); 

당신은 null 객체를 사용하려고하고, (물론) 그 (이것은 내가 대화 상자를 만드는 방법입니다 NullPointerException

가 발생합니다 여기

LayoutInflater factory = LayoutInflater.from(this); 
final View textEntryView = factory.inflate(R.layout.dialogo_layout, null); 
final AlertDialog.Builder resetQuestion = new AlertDialog.Builder(YourActivity.this) 
// do whatever you want with the resetQuestion AlertDialog 

, R.layout.dialogo_layout 담당자 : 그리고 나는) 그것을 할 수있는 최선의 방법이라고 생각 대화 상자 레이아웃이 포함 된 res/layout 디렉토리에 dialogo_layout.xml이라는 파일을 다시 보내십시오.

+0

이클립스가 제안했듯이, 필자는 그 것이 필요하다고 생각했다. – Fraser