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

getImageId();

Hi, How are you doing, Im having trouble on getImageId(); because it shows red, then, the getDrawable is cross... there is error showed in Log Cat...

but if I click alt+enter on getImageId(); it showed Create Getter,Create Property and Create Method.

     private void loadPage() {

     Page page = mStory.getPage(0);

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

     String pageText = page.getText();
     //Add the name if placeholder included.  Wont add if no placeholder

     pageText = String.format(pageText, mName);
     mTextView.setText(pageText);

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

 }```

2 Answers

Hi James,

Yeah, it was typo. Hooray. How about getDrawable it keep getting crossed. It highlights 'getDrawable(int) is depcrecated'...

You're probably using API 22 then, in which the getDrawable(int) method was deprecated. Instead you could use ContextCompat from the support library.

ContextCompat.getDrawable(this, R.drawable.your_drawable);

where "this" is your context(likely your activity), and then R.drawable.your_drawable is the result of getImageId(). I'm not sure if this is the best way for this or not, but you might be able to get some more info from a stackoverflow posting here.

Thanks. It really help from the stack overflow website.

Hello,

It looks like you might have a typo in getImageid(). In the demo, they used getImageId(). I'd recommend double checking your casing both in this file and your Page.java file.