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

Leonard Morrison
PLUS
Leonard Morrison
Courses Plus Student 32,914 Points

Imageview not found apparently.....

Here's my code for the StoryActivity: public class StoryActivity extends Activity{ public static final String TAG = StoryActivity.class.getSimpleName(); public Story story = new Story(); public ImageView storyImage; public TextView storyText; public Button choice1; public Button choice2; public String Name; Page currentPage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_story);
    Intent intent = getIntent();
    Name = intent.getStringExtra("name");

    if(Name == null)
    {
        Name="Dude";
    }
    storyImage = (ImageView)findViewById(R.id.storyImage);
    storyText = (TextView)findViewById(R.id.storyText);
    choice1 = (Button)findViewById(R.id.choiceButton1);
    choice2 = (Button)findViewById(R.id.choiceButton2);
    loadPage(0);
   }

private void loadPage(int choice)
{

    currentPage = story.getPage(0);
    Log.d(TAG, "Getting image source....");

     //Here's where the apparent error is
    storyImage.setImageDrawable(ContextCompat.getDrawable(this, currentPage.getImageID()));

    String pageText = currentPage.getTextID();
    //Adds name if the placeholder is included
    pageText = String.format(pageText, Name);
    storyText.setText(currentPage.getTextID());
    choice1.setText(currentPage.getChoice1().toString());
    choice2.setText(currentPage.getChoice2().toString());
    choice1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int nextPage = currentPage.getChoice1().getNextPage();
            loadPage(nextPage);
        }
    });
    choice2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v)
        {
            int nextPage = currentPage.getChoice2().getNextPage();
            loadPage(nextPage);

        }
    });

   /* if(currentPage.isEnding())
    {
        choice1.setVisibility(View.INVISIBLE);
        choice2.setText("Play again");
        choice2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }*/
    //storyImage.setImageDrawable();



}

}

Error message: 05-16 03:17:42.420 20725-20725/leban.nait.ca.interactivestory E/AndroidRuntime: FATAL EXCEPTION: main Process: leban.nait.ca.interactivestory, PID: 20725 java.lang.RuntimeException: Unable to start activity ComponentInfo{leban.nait.ca.interactivestory/leban.nait.ca.interactivestory.StoryActivity}: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) at android.app.ActivityThread.access$800(ActivityThread.java:135) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method) Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0 at android.content.res.Resources.getValue(Resources.java:1123) at android.content.res.Resources.getDrawable(Resources.java:698) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323) at leban.nait.ca.interactivestory.StoryActivity.loadPage(StoryActivity.java:57) at leban.nait.ca.interactivestory.StoryActivity.onCreate(StoryActivity.java:48) at android.app.Activity.performCreate(Activity.java:5231) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)  at android.app.ActivityThread.access$800(ActivityThread.java:135)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:136)  at android.app.ActivityThread.main(ActivityThread.java:5001)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:515)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)  at dalvik.system.NativeStart.main(Native Method)