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 trialKyle Baker
8,211 PointsMy second screen is not loading correctly, help?
Pressing start your adventure on the first screen leads to a blank screen instead of what was intended. Here is my code and as I don't exactly know where the problem is, please ask for more of it if necessary.
Story.java
package com.example.kyba.interactivestory.model;
import com.example.kyba.interactivestory.R; import com.example.kyba.interactivestory.ui.StoryActivity;
public class Story { private Page[] mPages;
public Story() {
mPages = new Page[7];
mPages[0] = new Page(
R.drawable.page0,
"On your return trip from studying Saturn's rings, you hear a distress signal that seems to be coming from the surface of Mars. It's strange because there hasn't been a colony there in years. Even stranger, it's calling you by name: \"Help me, %1$s, you're my only hope.\"",
new Choice("Stop and investigate", 1),
new Choice("Continue home to Earth", 2));
mPages[1] = new Page(
R.drawable.page1,
"You deftly land your ship near where the distress signal originated. You didn't notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century.",
new Choice("Explore the cave", 3),
new Choice("Explore the rover", 4));
mPages[2] = new Page(
R.drawable.page2,
"You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low.",
new Choice("Head back to Mars to investigate", 4),
new Choice("Continue home to Earth", 6));
mPages[3] = new Page(
R.drawable.page3,
"Your EVA suit is equipped with a headlamp, which you use to navigate the cave. After searching for a while your oxygen levels are starting to get pretty low. You know you should go refill your tank, but there's a very faint light up ahead.",
new Choice("Refill at ship and explore the rover", 4),
new Choice("Continue towards the faint light", 5));
mPages[4] = new Page(
R.drawable.page4,
"The rover is covered in dust and most of the solar panels are broken. But you are quite surprised to see the on-board system booted up and running. In fact, there is a message on the screen: \"%1$s, come to 28.543436, -81.369031.\" Those coordinates aren't far, but you don't know if your oxygen will last there and back.",
new Choice("Explore the coordinates", 5),
new Choice("Return to Earth", 6));
mPages[5] = new Page(
R.drawable.page5,
"After a long walk slightly uphill, you end up at the top of a small crater. You look around, and are overjoyed to see your favorite android, %1$s-S1124. It had been lost on a previous mission to Mars! You take it back to your ship and fly back to Earth.");
mPages[6] = new Page(
R.drawable.page6,
"You arrive home on Earth. While your mission was a success, you forever wonder what was sending that signal. Perhaps a future mission will be able to investigate...");
}
}
Page.java
package com.example.kyba.interactivestory.model;
public class Page { private int mImageId; private String mText; private Choice mChoice1; private Choice mChoice2; private boolean mIsFinal = false;
public boolean isFinal() {
return mIsFinal;
}
public void setIsFinal(boolean isFinal) {
mIsFinal = isFinal;
}
public Page(int imageId, String text, Choice choice1, Choice choice2) {
mImageId = imageId;
mText = text;
mChoice1 = choice1;
mChoice2 = choice2;
}
public Page(int imageId, String text) {
mImageId = imageId;
mText = text;
mChoice1 = null;
mChoice2 = null;
mIsFinal = true;
}
public int getImageId() {
return mImageId;
}
public void setImageId(int imageId) {
mImageId = imageId;
}
public String getText() {
return mText;
}
public void setText(String text) {
mText = text;
}
public Choice getChoice1() {
return mChoice1;
}
public void setChoice1(Choice choice1) {
mChoice1 = choice1;
}
public Choice getChoice2() {
return mChoice2;
}
public void setChoice2(Choice choice2) {
mChoice2 = choice2;
}
}
Choice.java
package com.example.kyba.interactivestory.model;
public class Choice { private String mText; private int mNextPage;
public Choice(String text, int nextPage) {
mText = text;
mNextPage = nextPage;
}
public String getText() {
return mText;
}
public void setText(String text) {
mText = text;
}
public int getNextPage() {
return mNextPage;
}
public void setNextPage(int nextPage) {
mNextPage = nextPage;
}
}
content_story.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior" tools:context=".ui.StoryActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/storyImageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/page0"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="You deftly land your ship near where the distress signal originated. You didn't notice anything strange on your fly-by, but there is a cave in front of you. Behind you is an abandoned rover from the early 21st century."
android:id="@+id/storyTextView"
android:layout_below="@+id/storyImageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingTop="15dp"
android:lineSpacingMultiplier="1.2"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop and Investigate"
android:id="@+id/choiceButton2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/white"
android:textColor="#FF3A8AEC"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Continue Home to To Earth"
android:id="@+id/choiceButton1"
android:layout_above="@+id/choiceButton2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="@android:color/white"
android:textColor="#3a8aec"/>
</RelativeLayout>
StoryActivity.java
package com.example.kyba.interactivestory.ui;
import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; import android.view.View;
import com.example.kyba.interactivestory.R; import com.example.kyba.interactivestory.model.Page;
public class StoryActivity extends AppCompatActivity { 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();
String name = intent.getStringExtra(getString(R.string.key_name));
if (name == null) {
name = "Friend";
}
Log.d(TAG, name);
}
}
4 Answers
Darnell Cephus
4,208 PointsYou probably didn't make the change in your Android Manifest file. It is located in the Manifests folder
under your main activity closing tag insert:
<activity android:name=".UI.StoryActivity" android:label="StoryActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme"> <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".UI.MainActivity"/> </activity>
Monis bana
202 PointsDo what Darnell Cephus suggested and then build ->rebuild project then Run the project
Kyle Baker
8,211 PointsTried but it's still not working. At this point, I finished the course but the app just crashes every time I try to go past the beginning of the app. I'm getting this "08-24 10:48:09.982 260-797/? E/NetlinkEvent: NetlinkEvent::FindParam(): Parameter 'LABEL' not found"
Tobias Ofenberger
994 PointsI've exactly the same problem and couldn't solve it yet
Tobias Ofenberger
994 PointsOK in my case I solved it. I forgot to add
setContentView(R.layout.activity_story);
to the StoryActivity.java file
Kyle Baker
8,211 PointsKyle Baker
8,211 PointsThat isn't it, I did the portrait update to the android manifest file and I just checked it to make double sure I had everything. Turns out I have more, an android:parentActivityName=".ui.MainActivity". But, even removing that I was unable to make the code work. Any other ideas? Thanks for the attempt