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


Ray Kennedy
Ray Kennedy
Courses Plus Student 2,982 Points

Drawable is deprecated How should I structure my code

I am following the story application and when I write the following code

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

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

        String pageText = page.getText();

        //This will add the name if placeholder included
        pageText = String.format(pageText, mName);


this "get drawable" has a line drawn through it.

I've tried it like this: Drawable drawable = getResources().getDrawable(page.getImageId(), null); but that makes the system bark errors at me. Any help would be greatly appreciated.

1 Answer


One way to make it so this is compatible both backwards and forwards is to use the ContextCompat class from the support library.

For example change

Drawable drawable = getResources().getDrawable(mCurrentWeather.getIconId());


Drawable drawable = ContextCompat.getDrawable(this, mCurrentWeather.getIconId());

You also need to make sure you're importing the right class, but I believe just using the optimize your imports command should bring in the right one as long as the support library is included in your build.gradle file.