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

jenyufu
jenyufu
3,311 Points

Getting Data from Intent Challenge error Part 2 of 2

Here is the code:

import android.os.Bundle;

public class FlightActivity extends Activity {

  public int mFuelLevel = -1;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flight);

    // Add your code below!
    Intent intent = getIntent();
    String name = intent.getStringExtra("FUEL_LEVEL");
  }
}

Don't know why its not working

The error says:

./FlightActivity.java:14: error: cannot find symbol String name = intent.getStringExtra("FUEL_LEVEL"); ^ symbol: method getStringExtra(String) location: variable intent of type Intent 1 error

1 Answer

jenyufu
jenyufu
3,311 Points

Nevermind, I got the answer: I need to change:

    String name = intent.getStringExtra("FUEL_LEVEL");

to

    Integer name = intent.getIntExtra("FUEL_LEVEL", -1);

Because unlike the example, we are passing in an Int, not a String

Darren Fisher
Darren Fisher
1,071 Points

Could you please explain why the -1 is needed? I do not remember seeing anything about this during the course. Thanks in advance

jenyufu
jenyufu
3,311 Points

If I recall correctly Its because we are also passing in an Int. which in this case is -1. Not just the String: "FUEL_LEVEL"