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 Loading the First Page

Interactive Story: "Can't resolve method 'getPage(int)'

the error asks me to create a method for this which i already did. package me.mars.UI;

import android.graphics.drawable.Drawable; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.content.Intent; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

import me.mars.Model.Page; import me.mars.R;

public class Story extends ActionBarActivity {

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

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);
    Intent intent = getIntent();
    mName = intent.getStringExtra(getString(R.string.key_name));

    Toast.makeText(Story.this, mName, Toast.LENGTH_LONG).show();

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

    loadPage();


}

private void loadPage(){
    Page page = mStory.getPage(0);

    Drawable drawable = getResources().getDrawable(page.getImageId());
    mImageView.setImageDrawable(drawable);

    String pageText = page.getText();
    // add name if PH is there else it does nothing
    pageText = String.format(pageText, mName);
    mTextView.setText(pageText);

    mChoice1.setText(page.getChoice1().getText());
    mChoice2.setText(page.getChoice2().getText());
}

} this is my story.java file and below is my storys.java package me.mars.UI;

import android.graphics.drawable.Drawable; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.content.Intent; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;

import me.mars.Model.Page; import me.mars.R;

public class Story extends ActionBarActivity {

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

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);
    Intent intent = getIntent();
    mName = intent.getStringExtra(getString(R.string.key_name));

    Toast.makeText(Story.this, mName, Toast.LENGTH_LONG).show();

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

    loadPage();


}

//all the pages are here and at the bottom is public Page getPage(int pageNumber) { return mPages[pageNumber]; }

}

1 Answer

Hello,

I would actually recommend for starters that you name your activity Story class to be StoryActivity. Right now, Android is looking for a getPage() from within your Story activity and not your Story model class. Keeping classes named differently will help cut down on that confusion. The alternative is that you'll have to reference the full path of each class.

Second, it looks like to me you either posted the same class twice or you're trying to have your Story model class as an Activity. If it is also an Activity it will likely cause problems as well.

Let me know if this helps or if you need more assistance. If you could post updated code of both the Story activity class and the Story model class that would help in assisting you further.