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 trialUnsubscribed User
3,268 PointsNeed Help with Task 2 after this video
Hi Ben could you plese help as i can't seem to get past Tast 2?
MUZ140118 Cathrine Makuya
10,300 Pointscan you help on the task 1
3 Answers
Jeremy Faith
Courses Plus Student 56,696 PointsI have to assume this is the question you are asking about(Task 2 from Using a Model in the Controller).
Now that we have a model object, update the TextView to use the Spaceship's type property. Remember to use the helpful getter method!
You will need to set the text for the TextView mTypeLabel using mSpaceship's getType method provided. Your answer should look like this.
mTypeLabel.setText(mSpaceship.getType());
MUZ140118 Cathrine Makuya
10,300 Pointshue can you help me on the task 1 .l am failing to solve it
MUZ140118 Cathrine Makuya
10,300 Pointshie can you help me on the task 1 .l am failing to solve it
brandtvavasour
4,636 PointsI can't solve the third one -__-, any help?
Jeremy Faith
Courses Plus Student 56,696 Pointsbrandtvavasour, first you will need to call the setText method on mPassengersField.
mPassengersField.setText();
Inside setText, you need to get mSpaceship's number of passengers using constructor getNumPassengers(). Since the return value is an int need to convert to a string for the setText() method.
Integer.toString(mSpaceship.getNumPassengers())
Finally, you code should look like this.
mPassengersField.setText(Integer.toString(mSpaceship.getNumPassengers()));
brandtvavasour
4,636 PointsThanks heaps Jeremy Faith!
Ivan Solodov
1,552 PointsJeremy , thanks alot ! I have a follow up question , I cant recall we learned Integer.toString method .
how come : """ mPassengersField.setText(mSpaceship.getNumPassengers().toString()); """ does not work ? Is it wrong ?
Vishnu Ravindran
4,220 PointsThank you very much Jeremy. Well as Ivan has pointed out since we have not learned the Integer.toString method, instead of the code
Integer.toString(mSpaceship.getNumPassengers())
We can use the code below
String.format("%s",mSpaceship.getNumPassengers())
Where ā%sā would be the format specifier for String. Refer the Formatting String Syntax Documentation in the video to read more.
So our final code would be
mPassengersField.setText(String.format("%s",mSpaceship.getNumPassengers()));
Please do correct me if I am wrong. Thanks
Unsubscribed User
3,268 PointsThank you
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 Pointsl need help on the task 1