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 Formatting Strings

..I'M LOST! PLEASE HELP

Hi,just want to ask.. im using android-studio-bundle-141.1903250-windows, im confused in the codes when Ben typed the Drawables: Here are the codes that i wrote from the video. Drawable drawable = getResources().getDrawable(page.getImageId()); mImageView.setImageDrawable(drawable); the getDrawable has a strike through in it and when i hover the pointer ..it says that deprecated.and im getting an error on the text when it is displays on the emulator.. it doesnt take the string that i entered and it just shows "%1$s" on the textfield.. also..i noticed that Ben uses Drawables, but on mine was Mipmap.. are they different ? also in code? thanks ..

2 Answers

Depending on the version of Android Studio you're running Drawables has been deprecated and stuff should go in the folder labeled mipmap. For example where Ben says drawable-mpdi for the folder it would be mipmap-mpdi for the folder name. When he types (R.drawable.fileName) you would use (R.mipmap.fileName). I had this issue as well at first. Let me know if this helped you out.

Ah i see.. but how about in this code? : Drawable drawable = getResources().getDrawable(page.getImageId()); mImageView.setImageDrawable(drawable); the getDrawable has a strikethrough in it...i'm a bit confused of the R.drawable.fileName to R.mipmap.fileName..how can i change all Drawables to mipmap in this code? thanks for the first answer :D..hope you can help me in this one too

Albert Gutierrrez I am not 100% sure the finer working of it though I can say that yesterday I managed to run some code that was just like this.

In StoryActivity I am still using Drawables as I didn't find a better way to go about it, however in the Story class (model) I am setting to getImageId to a mimmap. The Page class (model) is looking for an id, text, choice1 and choice2 in that order so in the Story class (model) the first parameter its gonna get is my R.mipmap.page#

StoryActivity

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

Page class (model)

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

Story Class (model)

 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));

As far the "%1$s" showing up instead of your name. I had the same problem my problem was these three lines (minus comment line) one of them I forgot to set... I believe it was the last line.

        String pageText = mCurrentPage.getText();
        // Add the name if placeholder is included. Won't add if placeholder is not included.
        pageText = String.format(pageText, mName);
        mTextView.setText(pageText);

Ok..sadly i did what you have told..by still gives me the depracated error and cant return anything.. :(. Maybe I'll try and try until I die to this one and maybe I'll figure it out in the future..anyways.. thank you so much for the help :D.it enlightens my thoughts for the drawables to mipmap, it gave me a bit of understanding..(well in my case though :D). thank you kind sir. Have a blessed day

Don't give up. take a break and come back to it. I am new to Android development and thus far when I hit a wall that I can't seem to figure out taking a small break usually helps me come back with a fresh set of eyes. You can do this!

Ok thanks for the encouragement. I'll try to fix the code and try to repeat and fully understand the tutorials..and I'll make your answers as reference. Thank you :).

Juan Ferr
Juan Ferr
13,220 Points

Same problem as John Welan. I was setting mTextView.setText(pageText); twice