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 Additional Pages

storyImageView/storyTextView issues

Im gettting errors at the lines: mImageView = (ImageView)findViewById(R.id.storyImageView);

mTextView = 

(TextView)findViewById(R.id.storyTextView);

The red squigglys are under storyImageView/storyTextView.

Its says they cannot be resolved as a field. Im not sure what is wrong

package ui;

import model.Story; import model.Page;

import com.lukan.signalsfrommars.R; import com.lukan.signalsfrommars.R.layout; import com.lukan.signalsfrommars.R.string;

import android.app.Activity; import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

public class StoryActivity extends Activity{

private Story mStory = new Story();
private ImageView mImageView;
private TextView mTextView;
private Button mChoice1;
private Button mChoice2;
private String mName;
private Page mCurrentPage;
public static final String TAG = StoryActivity.class.getSimpleName();

  @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.storyImageView);
        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){
      mCurrentPage= mStory.getPage(choice);
      Drawable drawable = getResources().getDrawable(mCurrentPage.getmImageId());
      mImageView.setImageDrawable(drawable);
      String pageText= mCurrentPage.getmText();
      pageText = String.format(pageText, mName);

      mTextView.setText(mCurrentPage.getmText());
      mChoice1.setText(mCurrentPage.getmChoice1().getmText());
      mChoice2.setText(mCurrentPage.getmChoice2().getmText());

      mChoice1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        int nextPage = mCurrentPage.getmChoice1().getmNextPage();
        loadPage(nextPage);
        }
    });

      mChoice2.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
            int nextPage = mCurrentPage.getmChoice2().getmNextPage();
            loadPage(nextPage);
            }
        });

  }

}

1 Answer

Anthony Foster
Anthony Foster
1,280 Points

It sounds like the resource id isn't resolving. Double check the id listed in the activity_story.xml. For the ImageView you should see this:

android:id="@+id/storyImageView"