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 Formatting Strings

Trying to run the Story Activity but its saying unfortunately, Interactive Story has stopped working

Here is my piece. Failing to find were l got wrong

package com.example.alfred.interactivestory.ui;

import android.content.Intent; //import android.graphics.drawable.Drawable; //import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.util.Log;

import android.widget.Button; import android.widget.ImageView; import android.widget.TextView;

import com.example.alfred.interactivestory.R; import com.example.alfred.interactivestory.model.Page; import com.example.alfred.interactivestory.model.Story;

public class StoryActivity extends ActionBarActivity { // private Page[] mPages; public static final String TAG = StoryActivity.class.getSimpleName(); private Story mStory = new Story(); private ImageView mImageView; private TextView mTextView;

private Button mChoice1;
private Button mChoice2;
private  String mName;



@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);
  //  mPages = new Page[7];

    mImageView = (ImageView) findViewById(R.id.storyImageView);
    mTextView = (TextView) findViewById(R.id.storyTextView);
    mChoice1 = (Button) findViewById(R.id.choiceButton1);
    mChoice1 = (Button) findViewById(R.id.choiceButton2);

    loadPage();
}

private void loadPage(){

    Page page = mStory.getPage(0);

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

    String pageText = page.getText();
    //Add the name if placeholder included. Wont if no placeholder
    pageText = String.format(pageText, mName);

    mTextView.setText(pageText);

    mChoice2.setText(page.getChoice2().getText());

}

}

1 Answer

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

Hi,

Looks like a small error that can be difficult to see. In your onCreate method you have:

  mChoice1 = (Button) findViewById(R.id.choiceButton1);
  mChoice1 = (Button) findViewById(R.id.choiceButton2);

The second line should probably be "mChoice2"

Seph Cordovano
Seph Cordovano
17,400 Points

Good catch! This was my error coincidentally as well! Thanks