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 trialNoah Schill
10,020 PointsCannot find symbol?
I'm not sure what's wrong.
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.getStringExtra("FUEL_LEVEL");
if (mFuelLevel == null) {
mFuelLevel = "-1";
}
}
}
1 Answer
Kristen Law
16,244 PointsHey Noah! If you head to the link they provided in the code challenge, it directs you to documentation that shows you which method to use on the intent: getIntExtra()
. I'll let you take a look at the documentation to see what parameters it takes in, but you won't be needing the if
statement.
Hope that helps! Let me know if you have further questions.
Noah Schill
10,020 PointsThank you, but I read the documentation and came up with this.
String mFuelLevel = getIntExtra(FUEL_LEVEL, -1);
It is telling me that it cannot recognise FUEL_LEVEL. I'm guessing this has something to do with referencing the FUEL_LEVEL in the other class? I'm lost xD
Kristen Law
16,244 PointsYou've almost got it! The getIntExtra()
method takes in a string and an int, so you'll need to pass in FUEL_LEVEL as a string: "FUEL_LEVEL"
.
Noah Schill
10,020 PointsSorry, but i'm still hitting a roadblock. Same error ;(
String mFuelLevel = getIntExtra("FUEL_LEVEL", -1);
I also tried
String mFuelLevel = intent.getIntExtra("FUEL_LEVEL", -1);
and
int mFuelLevel = getIntExtra("FUEL_LEVEL", -1);
Kristen Law
16,244 PointsSorry, I was only looking at the second half of the statement. The intent.getIntExtra("FUEL_LEVEL", -1)
part is correct, but mFuelLevel is an int, and it is already defined at the top of the class, so all you need to do is assign a value to it.
Noah Schill
10,020 PointsNoah Schill
10,020 PointsYes! That worked exactly! Thank you!