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 the Story

page0 is not populating when typing out the setImageID(R.drawable.page0) method. Why is my code missing page0 ?

I'm on the "Creating the Story" video and I am working in the Story class. I have the constructor built out up to the part where I am trying to draw page0. When typing the method mPages[0].setImageId(R.drawable.page0); the "page.0" is not available within the dot syntax. What did i miss? How do i get the page0 option to show up in the predictive options when writing this method?

Josh Gold
Josh Gold
12,207 Points

Not sure, but for Android Studio the resource or image needs to be located in the drawable folder for the predictive feature to work of course. If your resource is not in the drawable folder, obviously Android Studio won't be able to find it.

Also for what its worth you listed both page.0 and page0 in your question.

3 Answers

Josh Gold
Josh Gold
12,207 Points

I took a look at my own InteractiveStory app from when I did the same tutorial. My page0 PNG image file is located in mipmap folders. So if you want to access these images programatically, you need to point Android to the mipmap folders, not to the drawable folders.

Usually mipmap folder is for main program icon, and drawable is for other images. Maybe a few years back when this tutorial was created mipmap folder was used for more general graphics, I don't know.

Anyhow in Story.java for example, I point android to the page0 image like this:

   mPages[0] = new Page(
                R.mipmap.page0,
                "On your return trip from studying Saturn's rings, you hear a distress signal that seems to be coming from the surface of Mars. It's strange because there hasn't been a colony there in years. Even stranger, it's calling you by name: \"Help me, %1$s, you're my only hope.\"",
                new Choice("Stop and investigate", 1),
                new Choice("Continue home to Earth", 2));

page0.png is in all the approbate drawable minmap sub folders folders.

page.0 was a typo in the comments not in my code.

I tried syncing the gradle project and that didn't resolve it.

When I command+click on it using mac, it says "Cannot find declaration to go to". Is there an xml file I need to update to let it know about the images?

Here is my Page.class file:

<p>

public class Page { private int mImageId; private String mText; private Choice mChoice1; private Choice mChoice2;

public int getImageId() {
    return mImageId;
}

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

public String getText() {
    return mText;
}

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

public Choice getChoice1() {
    return mChoice1;
}

public void setChoice1(Choice choice1) {
    mChoice1 = choice1;
}

public Choice getChoice2() {
    return mChoice2;
}

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

} </p>

Thank you sir, problem solved. they need to update their tutorial. Totally makes sense and thanks again.