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

I have this error : java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setI

package com.xstudios.interactivestoryapp.ui;

import android.content.Intent; import android.graphics.drawable.Drawable; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

import com.xstudios.interactivestoryapp.R; import com.xstudios.interactivestoryapp.model.Page; import com.xstudios.interactivestoryapp.model.Story;

public class StoryActivity extends AppCompatActivity { public static final String TAG = StoryActivity.class.getSimpleName(); private ImageView mImageView; private TextView mTextView; private Button mchoice1; private Button mchoice2; private String mName;

private Story mStory = new Story();
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);
    Intent intent = getIntent();
           mName= intent.getStringExtra(getString(R.string.key_name));
    if(mName==null)
    {
        mName ="Friend";
    }

    Log.d(TAG, mName);
    mImageView = (ImageView) findViewById(R.id.imageView);
    mTextView = (TextView) findViewById(R.id.storytextView);
    mchoice1 = (Button) findViewById(R.id.Choicebutton1);
    mchoice2 = (Button) findViewById(R.id.ChoiceButton2);
    loadPage(0);
}


private void loadPage(int choice)
{

    final Page mCurrentPage = mStory.getPage(0);
    Drawable drawable = ResourcesCompat.getDrawable(getResources(), mCurrentPage.getImageid(),null);

mImageView.setImageDrawable(drawable); String pageText = mCurrentPage.getText(); pageText = String.format(pageText, mName); if(mCurrentPage.isFinal()) { mchoice1.setVisibility(View.INVISIBLE); mchoice2.setText("Play Again"); mchoice2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); } }); } else { mTextView.setText(pageText); mchoice1.setText(mCurrentPage.getMchoice1().getText()); mchoice2.setText(mCurrentPage.getChoice2().getText());

mchoice1.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        int nextPage = mCurrentPage.getMchoice1().getNextPage();
        loadPage(nextPage);
    }
});
mchoice2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        int nextPage = mCurrentPage.getChoice2().getNextPage();
        loadPage(nextPage);
    }
});

} }

}

this is my code in StoryActivity.java.(Interactive story App by Ben) please help me