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 trial

Android Build an Interactive Story App (Retired) Intents and Multiple Activities Getting Data from an Intent

Noah Schill
Noah Schill
10,020 Points

Cannot find symbol?

I'm not sure what's wrong.

FlightActivity.java
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";
    }

  }
}
Noah Schill
Noah Schill
10,020 Points

Yes! That worked exactly! Thank you!

1 Answer

Hey 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
Noah Schill
10,020 Points

Thank 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

You'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
Noah Schill
10,020 Points

Sorry, 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);

Sorry, 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.