in my function there is a warning about the return (This function has a return type of ‘int’, but doesn’t end with a return statement. ) but I dont know what is the problem . any idea?
int checkValueIndex() {
if (selectedValue != null) {
for (int i = 0; i < mList.length; i++) {
if (mList[i].name == selectedValue.name) {
return i;
}
}
} else {
return null;
}
}
2
Answers
Error says you have to return some
int
value. Add?
in return type so that you can allow returnnull
value as well.try this code:
Your function return null value ,add (?) so it will accept null as follow: