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) Finishing the User Interface Using a Model in the Controller

Jordan Ernst
Jordan Ernst
5,121 Points

somebody please help me with this question.

please review my code for this question i am on the last question of this chapter and i don't know where in the videos Ben explained this. i know e must of but i think the info was presented differently and this is confusing the crap out of me. i may be over thinking it. i think this final snippet of code is the closest i have gotten thus far.

LandingActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LandingActivity extends Activity {

    public Button mThrustButton;
    public TextView mTypeLabel;
    public EditText mPassengersField;// return the text the textView is displaying

    public Spaceship mSpaceship;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landing);

        mThrustButton = (Button)findViewById(R.id.thrustButton);
        mTypeLabel = (TextView)findViewById(R.id.typeTextView);
        mPassengersField = (EditText)findViewById(R.id.passengersEditText);

        mSpaceship = new Spaceship("FIREFLY");
        mTypeLabel.setText(mSpaceship.getType());//returns the value of getType= String mType
        mPassengersField= mSpaceship.setText();
          mSpaceship.setNumPassengers(mSpaceship.getNumPassengers());// mSpaceship.setNumPassengers(mSpaceship.getNumPassengers()); make sure you 'set' the 'text' of m PassengersField
        // Add your code here!
    }
}
Spaceship.java
public class Spaceship {
    private String mType;
    private int mNumPassengers = 0;

    public String getType() {
      return mType;
    }

    public void setType(String type) {
      mType = type;
    }

    public int getNumPassengers() {
      return mNumPassengers;
    }

    public void setNumPassengers(int numPassengers) {
      mNumPassengers = numPassengers;
    }

    public Spaceship() {
      mType = "SHUTTLE";
    }

    public Spaceship(String type) {
      mType = type;
    }
}

2 Answers

Kevin Faust
Kevin Faust
15,353 Points

Hey Jordan,

You just about got it!

mSpaceship.setNumPassengers(mSpaceship.getNumPassengers());

So what we want to do is set our mSpaceship (an edit text) to value of the getNumPassengers() method right? What you are doing right now is calling the setNumPassengers method on a edit text which doesnt make sense as that method only exists in the spaceship class.

Also getNumPassengers returns an int value. Edit texts only accept Strings. What can we do about this?

Well let's see

So first we want to set the text of our mPassengersField. We do this by the following:

mPassengersField.setText();

We pass our getNumPassengers method inside of it

mPassengersField.setText(mSpaceship.getNumPassengers());

But we have to convert the int to a string. so do this:

 + ""

complete product:

mPassengersField.setText(mSpaceship.getNumPassengers()  + "" );
Jordan Ernst
Jordan Ernst
5,121 Points

thanks buddy! i actually just made a new int variable and converted using Integer.toString(x) x being the variable. i figured this out about 10 mins after i asked the question. thanks for your time though!

Kevin Faust
Kevin Faust
15,353 Points

no problemo. glad we got it workin !