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

Tommy Binkley
Tommy Binkley
18,584 Points

Problem With Drawables

I put in

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

and the | getDrawable | text has a line through the whole text and a little note says "getDrawable(int)" is deprecated.

Also at the top of the page | ActionBarActivity | also has a line through it with the same message.

How can I fix this, so i can continue.

2 Answers

Hello,

To get around the deprecation(and use the new setups for these), you'll want to replace ActionBarActivity with AppCompatActivity(remember to import the class). You'll also want to change the

getResources().getDrawable(page.getImageId());

to

ContextCompat.getDrawable(this, page.getImageId());

In the example above, "this" should be replaced with the current Context(which would likely be your Activity so leaving "this" in for this case would be fine). Please let us know if this helps or if you need more assistance. If you need more assistance, please provide your updated code so that we can help you from your current setup.

Conrad Spotts
Conrad Spotts
11,768 Points

Hi Tommy, I hit this same issue today and I fixed it by changing the ActionBarActivity on the class line to:

public class StoryActivity extends Activity {

Ensure these two lines are in your imports: (they may have been added automatically for you if you fix your errors with the alt+enter technique in Android Studio)

import android.app.Activity;
import android.graphics.drawable.Drawable;

lastly, if you're still seeing the problem with getDrawable(int) make sure you are using the option for getDrawable(int id) in the auto completer list.

I was able to follow along without any other syntax changes for what he was using. Sorry for the late reply, hope this helps!