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 trialPeter Price
4,007 PointsGetting 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:
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
Treehouse TeacherAh, for Task 1 you just need the...
Intent intent = getIntent();
... line, that next line is the next step.
Ken
Ken Alger
Treehouse TeacherPeter;
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
Peter Price
4,007 PointsHI Ken,
Thanks for replying. I am definitely on Task 1. I will try again and post back the results.
Peter Price
4,007 PointsSame answer. Can you go to the top of this, and click on view challenge, copy my code and give it a try?
Peter Price
4,007 PointsI'll try that quickly
Peter Price
4,007 PointsThanks, 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
Treehouse TeacherFor Task 1 you should only have the:
Intent intent = getIntent();
line in the code challenge.
Ken Alger
Treehouse TeacherMeaning for the part we add to the code.
Peter Price
4,007 PointsThank 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".
Unsubscribed User
Courses Plus Student 401 Pointsimport 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
Peter Price
4,007 PointsThat is right.