Null Pointer Exception Using Checkbox
Solution 1:
If you are inflating a layout for your dialog
you need to use dialog object to initialize view
chkSubscribe = (CheckBox)dialog.findViewById(R.id.chkSubscribe);
You are getting NPE coz you have not initialized chkSubscribe
chkSubscribe = (CheckBox)findViewById(R.id.chkSubscribe)
//Initialization fails
You are also dismissing the dialog
in which case chkSubscribe
will be null.
Note : You can findViewById
of the current view hierarchy set to the activity.
Solution 2:
You are calling findViewById inside click, here it is not calling the findViewByid on the main activity class but the loginButton and loginButton does not have check box in it. you need to call this line "chkSubscribe = (CheckBox)findViewById(R.id.chkSubscribe); " in Activity and then reference it in the onClick method, remember any method you call on this object in onClick refer to loginButton not your activity
Post a Comment for "Null Pointer Exception Using Checkbox"