I’ve got 3 spinners and they’re doing the age old fun of when spinner one is selected it updates spinner two etc.
I’ve got a routine that when a spinner is changed, it runs this to update an edittext field with the values from the spinners.
However when the page loads it falls over (i’m assuming as theres nothing in spinner 3?)
public void updateLocalDesc(){
AssetType = spnAssetType.getSelectedItem().toString();
AssetGroup = spnAssetGroup.getSelectedItem().toString();
if(!spnAssetSubGroup.getSelectedItem().toString().equals("")){
AssetSubGroup = spnAssetSubGroup.getSelectedItem().toString();
tbLongDescription.setText(AssetType + " - " + AssetGroup + " - " + AssetSubGroup);
} else
{
tbLongDescription.setText(AssetType + " - " + AssetGroup);
}
}
As you can see i’m trying to protect out of it. My errors are: http://pastebin.com/y6x5iPNW
What line is the null pointer on? I imagine that it’s on
You should do a null check on
spnAssetSubGroup.getselectedItem()before callingtoString()on it. Something like:The error could also be on
getSelectedItem()returns null when there is no item selected, so you need to make sure to null check if some spinners aren’t going to have anything selected initially.