Richard Suarez
Richard Suarez

Reputation: 119

Dialog method does not work

I am trying to create a dialog method but when i call it, it causes a force close. The only thing i get on my log cat is:

dalvikvm thread=1: thread exiting with uncaught exception (group=0x40ab5c08)

FATAL EXCEPTION: main java.lang.NullPoinerExeption

im sure the rest is standard

here is a snipped of my code:

 Dialog PercentDialog;

 private void CreateDialog() {
    // TODO Auto-generated method stub
    Context context = Home.this;
    PercentDialog = new Dialog(context);
    //PercentDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    PercentDialog.setContentView(R.layout.percent_box);
    Button bOK = (Button) findViewById(R.id.bOK);
    Button bCancel = (Button) PercentDialog.findViewById(R.id.bCancel); 
    EditText etInt = (EditText) PercentDialog.findViewById(R.id.etInt); 
    TextView title = (TextView) PercentDialog.findViewById(R.id.tvTitle);   
    bOK.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
            // TODO Auto-generated method stub

        }

    });
    bCancel.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
            // TODO Auto-generated method stub
            PercentDialog.dismiss();
        }

    });

    PercentDialog.show();
}

Then i use CreateDialog(); to call my method but it is forced closed.

Upvotes: 0

Views: 70

Answers (1)

Sam
Sam

Reputation: 86948

Judging from your existing code, this line:

Button bOK = (Button) findViewById(R.id.bOK);

Should be:

Button bOK = (Button) PercentDialog.findViewById(R.id.bOK);

(Also please read about Java naming conventions which state that variables should start with a lowercase letter.)

Upvotes: 2

Related Questions