I want to check first if spinner has null values based on the following:
String Name= spinnerName.getSelectedItem().toString();
if(Name != null) {
} else {
}
is this a proper way? because i get
FATAL EXCEPTION: main java.lang.NullPointerException
on
String Name= spinnerName.getSelectedItem().toString();
I have declared it on Create
spinnerName
is null or ifgetSelectedItem()
returns null, callingtoString()
will cause your app to crash for NPEFunction for
Spinner
Item SelectionCheck condition for
selected Item
you can define a spinner for departure and destination like you did there, then inside a button
onClickListener
you can check for the value before starting a new activity for example:first you have to check either any item in the spinner selected or not and initialized or not