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 trialMUZ140118 Cathrine Makuya
10,300 Pointsstage 3 challenge 2
Next, we need getter and setter methods for our member variable. Let's start with the getter method. Add a method to get the value of mType.
public class Spaceship {
public String mType;
public String getType() {
return mType;
}
5 Answers
Jack Middlebrook
19,746 PointsFrom your posted code it looks like you are just missing a close bracket } at the end. Right now you have two open brackets and just one closed. Everything else looks good.
MUZ140118 Cathrine Makuya
10,300 Pointshere is my answer public String getType() { return mType; } correct me l dont know where l go wrong ...l have followed every step they say but nothing is working
Igor Gunger
8,113 Pointsme either I wrote my code correct even checked through android studio and It did not work for me
Igor Gunger
8,113 Pointspublic class Spaceship{
public String mShipType;
public String getShipType(){ return mShipType; }
}
//What is wrong with it? ******************
FRANK MAZORODZE
4,428 Pointsi removed the closing button and it worked
MUZ140118 Cathrine Makuya
10,300 PointsMUZ140118 Cathrine Makuya
10,300 Pointsthanks Jack it worked l have see my error
channonhall
12,247 Pointschannonhall
12,247 PointsIt still doesn't work Jack Can you help me?
Here's my code :
public class Spaceship { public String mType; } public String getType() { return mType; }
And it say's this :
Bummer! There is a compiler error. Please click on preview to view your syntax errors!
And in the Preview :
./Spaceship.java:4: error: class, interface, or enum expected public String getType() { ^ ./Spaceship.java:6: error: class, interface, or enum expected } ^ 2 errors
Can you help me jack?
Thanks Channon.
Jack Middlebrook
19,746 PointsJack Middlebrook
19,746 PointsHey Channon,
Looks like you are close. You just need to move your first closed bracket to the end of you code. Currently, your getType() method is not able to access the String variable mType because the closed bracket is right after mType; Make sure that your the first open bracket after Spaceship includes the whole block of code before putting the closing bracket.
Try the following and see if it will work for you:
channonhall
12,247 Pointschannonhall
12,247 PointsThanks Jack, Can you help me on task 4?
I don't know what to do.
Thanks Channon
EDIT: Already fixed ;)