Issue
I am trying to make a clean checkbox code in android but makes error if i just press the button and havent checked the checkbox this is the code of cleaning the checkbox:
public void fillDefaultDCN(MenuItem item){
int id = item.getItemId();
if(id == R.id.checkIt){
item.setChecked(false);
checkDCN = false;
}
}
And this is the code i have put on the RESET button
fillDefaultDCN(checkbox);
The checkbox is a declaration:
public MenuItem checkbox;
Apparently the Item.getItemId is null when the checbox is not checked and makes error.
Solution
Try this
public void fillDefaultDCN(MenuItem item){
if(checkbox == null){
//something
}else{
int id = item.getItemId();
if(id == R.id.checkIt){
item.setChecked(false);
checkDCN = false;
}
}
Answered By - Kostandin Vllahu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.