I'm following the Android book example:
//Get the drink from the intent
int drinkIdd = (Integer)getIntent().getExtras().get(EXTRA_DRINKID);
Drink drink = Drink.drinks[drinkIdd];
And this project could be ran in Android Studio but with a yellow warning on line:
int drinkIdd = (Integer)getIntent().getExtras().get(EXTRA_DRINKID);
with:
info: Unboxing of '(Integer)getIntent().getExtras().get(EXTRA_DRINKID)' may produce 'java.lang.NullPointerException'
From my understanding, get(EXTRA_DRINKID)
return an Object, and (Integer) converts it to int type to meet with int drinkIdd
.
- Could you tell me what this info means exactly, your answer will be appreciated for a beginner.
And could I write upper line like this? Using ( ) to wrap getIntent().getExtras().get() as a whole one since it finally return an object, and then convert it to int.
int drinkIdd = (Integer)(getIntent().getExtras().get(EXTRA_DRINKID));