Bishnu Kumar
Bishnu Kumar

Reputation: 129

Error:NullPointerException in android for dialog button click

edit_PASSWORD.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            final Dialog dialog = new Dialog(context);
            dialog.setContentView(R.layout.change_password);
            dialog.setTitle("Title...");
            EditText txtPassword = (EditText)  dialog.findViewById(R.id.changepwd);
            EditText txtVpassword = (EditText) dialog.findViewById(R.id.changevpwd);
            Button btnOk = (Button) findViewById(R.id.btnch_ok);
            Button btnCancle = (Button)           findViewById(R.id.btnch_cancle);
            btnCancle.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    //dialog.dismiss();
                }
            });
            dialog.show();
        }
    });
}

I am trying to create custom alert Dialog but when i click on btnCancle then program crash and get error:

Error:NullPointerException in android for button click

Sorry for the bad english.

Upvotes: 0

Views: 304

Answers (1)

Shivang Trivedi
Shivang Trivedi

Reputation: 2182

remove this

   Button btnOk = (Button) findViewById(R.id.btnch_ok); 

and put

   Button btnOk = (Button) dialog. findViewById(R.id.btnch_ok); 

same for btnCancle

Upvotes: 2

Related Questions