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) Intents and Multiple Activities Adding a Second Activity

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Runtime error on StoryActivity.java

So I followed the video and got some runtime errors when I tried to run the emulator.

I didn't quite understand the runtime errors completely but I did get the idea that the code might be looking for a different theme, one that uses an action bar that isn't actually being used.

So I looked at the Java file and commented out a line of code I thought might be relevant.

package uk.co.jonniegrieve.interactivestory;

import android.os.Bundle;
import android.app.Activity;

public class StoryActivity extends Activity {

     @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_story);
        //getActionBar().setDisplayHomeAsUpEnabled(true);
    }

}

So now the Emulator loads the second activity successfully. Did I do the right thing here or am I generating more errors here in the long run? :)

1 Answer

Hi Jonathan,

I think you can switch your activity to one that is compatible with an Action Bar - I don't think they are by default, but am probably wrong! Have a look at this for the AppCompat Activity and this for the Action Bar. They may assist, I hope.

There's a thread here that talks about different types of Activity that may help too.

Let me know how you get on!

Steve.

There's another thread here that talks about the deprecation.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Steve,

Yea the theme that's currently set in the preview is an AppCompat theme. I'm using a Holo.Light.NoActionBar theme in my code but when I select it in preview it tells me that there are several problems in Rendering and I need to use an AppCompat theme.

All very confusing.

I'm just thinking getActionBar().setDisplayHomeAsUpEnabled(true); is a deprecated line and should be removed. And now the changes I've made to the theme have messed up the manifest so I'm going back to square one. :)

I'm still getting the actionbar in the emulator even if I choose a no action bar theme which is what the project wants.