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

Getting Data from an Intent

My code looks right, but it shows this error message:

./FlightActivity.java:14: error: method getIntExtra in class Intent cannot be applied to given types;
    Integer name = intent.getIntExtra("FUEL_LEVEL");
                         ^
  required: String,int
  found: String
  reason: actual and formal argument lists differ in length
1 error

And this is MY code:

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 bellow
    Intent intent = getIntent();
    Integer name = intent.getIntExtra("FUEL_LEVEL");
  }
}

8 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Ah, for Task 1 you just need the...

Intent intent = getIntent();

... line, that next line is the next step. :wink:

Ken

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Peter;

Judging by the error message it looks like you are on Task 2 where the instructions state:

Now set mFuelLevel to the value from the Intent. Check the Intent documentation if you need help finding the correct
method to use. Use "FUEL_LEVEL" as the key and -1 as the default value.

In taking a look at the documentation for the method you chose, getIntExtra(), it takes a String and an int as parameters. Our task also wants us to set that value to mFuelLevel, not to an Integer named name.

Post back if you have further questions.

Happy coding,
Ken

HI Ken,

Thanks for replying. I am definitely on Task 1. I will try again and post back the results.

Same answer. Can you go to the top of this, and click on view challenge, copy my code and give it a try?

I'll try that quickly

Thanks, but it says now:

./FlightActivity.java:14: error: cannot find symbol
    Integer name = getIntExtra("FUEL_LEVEL");
                   ^
  symbol:   method getIntExtra(String)
  location: class FlightActivity
1 error
Ken Alger
Ken Alger
Treehouse Teacher

For Task 1 you should only have the:

Intent intent = getIntent();

line in the code challenge.

Ken Alger
Ken Alger
Treehouse Teacher

Meaning for the part we add to the code. :smile:

Thank you so much for your help. I didn't take out the line underneath at first, and that's what was messing it up.

If you add an answer to me I will select it as "best answer".

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 bellow
Intent intent = getIntent();

} }

//So everything that's up this comment

That is right.