Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build an Interactive Story App (Retired) Finishing the User Interface Ending the Story

Getting Error:Unfortunately App has Stoped working. plzzzzz help me!!!

When I write name and click button START YOUR ADVENTUR, App stopped by saying Unfortunately App has Stoped working.Plzzzzzz Help me.Here is code of Story activity:

" public class StoryActivity extends AppCompatActivity {

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) {
    final Page mCurrentPage = mStory.getPage(choice);
    Drawable drawable = getResources().getDrawable(mCurrentPage.getImageId());
    mImageView.setImageDrawable(drawable);

    String pageText = mCurrentPage.getText();
    //Add the name if placeholder is included otherwise not
    pageText = String.format(pageText, mName);
    mTextView.setText(pageText);

    if (mCurrentPage.isFinal()) {
        mChoice1.setVisibility(View.INVISIBLE);
        mChoice2.setText("PLAY AGAIN");
        mChoice2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    } else {
        mChoice1.setText(mCurrentPage.getChoice1().getText());
        mChoice2.setText(mCurrentPage.getChoice2().getText());

        mChoice1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int nextPage = mCurrentPage.getChoice1().getNextPage();
                loadPage(nextPage);
            }
        });

        mChoice2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int nextPage = mCurrentPage.getChoice2().getNextPage();
                loadPage(nextPage);
            }
        });
    }
}

} "

Ying Kiat Tiong
Ying Kiat Tiong
2,205 Points

Hey buddy, have you checked your log? What is the error that is being logged in your logcat?

There are a lot of errors in logcat, don't know where it came from and how to fix...... like this one: 03-22 02:29:30.050 674-685/com.android.systemui E/JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.) java.lang.RuntimeException: android.os.DeadObjectException at android.os.Parcel.writeException(Parcel.java:1373) at android.os.Binder.execTransact(Binder.java:410) at dalvik.system.NativeStart.run(Native Method) Caused by: android.os.DeadObjectException at android.os.BinderProxy.transact(Native Method) at android.content.IIntentReceiver$Stub$Proxy.performReceive(IIntentReceiver.java:124) at android.app.ActivityThread$ApplicationThread.scheduleRegisteredReceiver(ActivityThread.java:816) at android.app.ApplicationThreadNative.onTransact(ApplicationThreadNative.java:394)

Ying Kiat Tiong
Ying Kiat Tiong
2,205 Points

Hmm I don't think there is anything wrong with the code you pasted above. Can you please show me your MainActivity?

Ying Kiat Tiong
Ying Kiat Tiong
2,205 Points

Hmm..Sorry man I really can't spot any errors from your codes.. Perhaps you might wanna replay the tutorial to see if you have missed out some parts.

3 Answers

sure! Here is MainActivity: package com.example.shahzad.interactivestory.ui;

import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;

import com.example.shahzad.interactivestory.R;

public class MainActivity extends AppCompatActivity {

private EditText mNameEditText;
private Button mStartButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mNameEditText = (EditText) findViewById(R.id.nameEditText);
    mStartButton = (Button) findViewById(R.id.startButton);

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String name = mNameEditText.getText().toString();
            //Toast.makeText(MainActivity.this, name, Toast.LENGTH_LONG).show();
            startStory(name);
        }
    });
}
private void startStory(String name){

    Intent intent = new Intent(this, StoryActivity.class);
    intent.putExtra(getString(R.string.key_name), name);
    startActivity(intent);
}

@Override
protected void onResume() {
    super.onResume();
    mNameEditText.setText("");
}

}

it's ok. Thank you for your response. Would u like to give ur contact info like skype ?

Hello marsh i look at your code and note it that you have in StoryActivity to many curly braces try to delete 1 or 2 and tell me your status after this :)