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 trialAnthony Beattie
4,942 Pointscode is not working to pass fuel level to flight activity. can anyone help please?
I've tried to look through my code, checking for capitals etc. its not passing, is there something I'm not seeing?
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class LaunchActivity extends AppCompatActivity {
public Button launchButton;
public int fuelLevel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launch);
// fuelLevel is set elsewhere.
// Code ommitted for brevity!
launchButton = (Button)findViewById(R.id.launchButton);
launchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Add your code in here!
Intent intent = new Intent(LaunchActivity.this, FlightActivity.class);
intent.putExtra("FUEL_LEVEL", mFuelLevel);
startActivity(intent);
}
});
}
}
1 Answer
Ben Deitch
Treehouse TeacherHey Anthony!
When your code fails, you can usually click on the 'Preview' button to see what the error was. In your case, your variable is declared as 'fuelLevel', but you're trying to use 'mFuelLevel' :)
Anthony Beattie
4,942 PointsAnthony Beattie
4,942 PointsThank you! On a similar note, is it better to know the basics of java before taking this course? although its called beginners android, it feels like I need to know what all the code means to follow along. However, if this is as simple as it gets, ill push through.
Ben Deitch
Treehouse TeacherBen Deitch
Treehouse TeacherYep, having a good understanding of Java really helps when it comes to understanding Android! There's 3 java courses listed as prereqs to the Build a Simple Android App course; they should be listed near the top.