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

Help!..Ending the story. Interactive story has stopped.

The log cat showed this: Please help.

at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5041)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)```

Hello,

Would you be able to provide the code for the activity?

package com.example.muhammadmumu.interactivestory.ui;

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

import com.example.muhammadmumu.interactivestory.R;

public class MainActivity extends ActionBarActivity {

private EditText mNameField;
private Button mStartButton;



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

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

    mStartButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick (View v){
            String name = mNameField.getText().toString();
            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();
    mNameField.setText("");
}

}

I have trouble on getting on the next page. like page 2 until finish.

Do you also have the code for your StoryActivity.java file?

package com.example.muhammadmumu.interactivestory.ui;

import android.content.Intent; import android.graphics.drawable.Drawable; import android.support.v4.content.ContextCompat; import android.support.v4.content.res.ResourcesCompat; import android.support.v7.app.ActionBarActivity; 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.example.muhammadmumu.interactivestory.R; import com.example.muhammadmumu.interactivestory.model.Page; import com.example.muhammadmumu.interactivestory.model.Story;

public class StoryActivity extends ActionBarActivity {

private 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;
private Page mCurrentPage;

@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 = ResourcesCompat.getDrawable(getResources(), mCurrentPage.getImageId(), null);
    mImageView.setImageDrawable(drawable);

    String pageText = mCurrentPage.getText();
    //Add the name if placeholder included.  Wont add if no placeholder

    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);

            }
        });

    }


}

}

oh ya, instead of ContextCompact, i use ResourcesCompact from previous discussion you helped.

Is there more to that error message in logcat? Anything that might be there could help in finding the needle in this haystack.

There is no error on Log Cat. But if I run it through emulators it will not run "Interactive Stories has stopped" However, if I run through GenyMotion it can run, but it will not run to Page 2 until Last Page.