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) The Model-View-Controller Pattern Creating a Data Model

stage 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.

Spaceship.java
public class Spaceship {
  public String mType;

    public String getType() { 
    return mType;
}

5 Answers

Jack Middlebrook
Jack Middlebrook
19,746 Points

From 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.

thanks Jack it worked l have see my error

It 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
Jack Middlebrook
19,746 Points

Hey 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:

public class Spaceship {
    public String mType;

    public String getType() { 
        return mType;
    }
}

Thanks Jack, Can you help me on task 4?

I don't know what to do.

Thanks Channon

EDIT: Already fixed ;)

here 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
Igor Gunger
8,113 Points

me either I wrote my code correct even checked through android studio and It did not work for me

Igor Gunger
Igor Gunger
8,113 Points

public class Spaceship{

public String mShipType;

public String getShipType(){ return mShipType; }

}

//What is wrong with it? ******************

i removed the closing button and it worked