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


Cannot resolve getPage() or getNextPage()

Here is my code:

public class StoryActivity extends Activity {

public static final String TAG= StoryActivity.class.getSimpleName();

private Story mStory = new Story();
private ImageView mImageView;
private TextView mTextView;
private Button mChoice1;
private Button mChoice2;
private String mName;
private Page mCurrentPage;

protected void onCreate(Bundle savedInstanceState) {

    Intent intent = getIntent();
    mName = intent.getStringExtra(getString(R.string.key_name));

    if (mName == null) {
        mName = "Friend";
    Log.d(TAG, mName);

    mImageView = (ImageView)findViewById(R.id.storyImageView);
    mTextView = (TextView)findViewById(R.id.storyTextView);
    mChoice1 = (Button)findViewById(R.id.choiceButton1);
    mChoice2 = (Button)findViewById(R.id.choiceButton2);



private void loadPage(int choice){
    mCurrentPage = mStory.getPage(choice);

    Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());

    String pageText =mCurrentPage.getText();
    pageText = String.format(pageText, mName);

    if (mCurrentPage.isFinal()) {
        mChoice2.setText("PLAY AGAIN");
        mChoice2.setOnClickListener(new View.OnClickListener(){
            public void onClick(View v) { finish();}



        mChoice1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                int nextPage = mCurrentPage.getChoice1().getNextPage();


        mChoice2.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                int nextPage = mCurrentPage.getChoice2().getNextPage();



I would really appreciate if someone could tell me where the error is coming from!

Your code looks fine, the problem might be in your Page.java file. Could you post the code from there?

Here's the Page.java:

public class Page { private int mImageId; private String mText; private Choice mChoice1; private Choice mChoice2; private boolean mIsFinal = false;

public Page(int imageId, String text, Choice choice1, Choice choice2) {
    mImageId = imageId;
    mText = text;
    mChoice1 = choice1;
    mChoice2 = choice2;

public boolean isFinal() {return mIsFinal;}

public void setFinal(boolean isFinal) { mIsFinal = isFinal;}

public Page (int imageId, String text) {
    mImageId = imageId;
    mText = text;
    mChoice1 = null;
    mChoice2 = null;
    mIsFinal = true;

public int getImageId() {return mImageId;}

public String getText() {return mText;}

public void setText(String text) {mText = text;}

public Choice getChoice1() {return mChoice1;}

public Choice getChoice2() {return mChoice2;}

public void setChoice2(Choice choice2) {mChoice2 = choice2;}

public void setImageId(int id) {mImageId = id;}

I added the line for setChoice1 after this

1 Answer

hm, that looks fine as well. Either the nextPage method in Choice is off, or one of the Page objects in the array that is in Story.java may have an error.