Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJames Richardson
2,496 PointsWhat am I doing wrong with the FUEL_LEVEL Intent. Error getIntExtra("FUEL_LEVEL", -1)
Everytime i add getIntExtra("FUEL_LEVEL", -1) it asks for String only in the error. When I remove the -1 it asks for a String and Int. Please help.
Many thanks.
James
import android.os.Bundle;
public class FlightActivity extends Activity {
public int mFuelLevel = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_flight);
// Add your code below!
Intent intent = getIntent();
String mFuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);
}
}
1 Answer
Patrick Corrigan
5,739 PointsString mFuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);
There are two things you need to do:
Remove the "String" from the beginning of the line. The variable has already been declared so you don't need a type here. If you were to define a new variable here it would need to be an int, not a String, because you are calling the getIntExtra method.
The getIntExtra method only takes one argument, in this case "FUEL_LEVEL" is the correct argument. The error you were getting when you tried this was because of the first issue I pointed out.
Hope this helps.
James Richardson
2,496 PointsJames Richardson
2,496 PointsThanks Patrick, you're a star!