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
Terence Evans
1,870 PointsInteractive Story project - "Start Your Adventure" button does nothing...still
I am working in the Interactive Story lesson and have typed everything as recommended. I have even downloaded the code from the site and compared it to mine. They appear identical. When I click on the button that says "Start Your Adventure" it changes shades for an instant but nothing happens. I have posted a similar question and got some great answers, but am still stuck in the mud. I would gladly copy and paste the code if it is worthwhile. I just had a thought. Could it be the location isn't being recognized? I was asked to post the error log. I assumed that it was the "catlog" it had nothing in it either.
5 Answers
Jacob Bergdahl
29,119 PointsThere could be many places where it goes wrong. Try to either A) Debug the code, or B) Place Log-statements on many places in the code to see where you go wrong.
Terence Evans
1,870 PointsSorry, as you can see from my point total, I am a rank rookie. When you suggest debugging, what do you mean? I tried clicking on the "debug" button and it just opened the Genymotion emulator, but I don't see the next steps.
Terence Evans
1,870 PointsLets see if I can find the correct way to post the code. """java.
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
public class MainActivity extends Activity {
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();
}
});
}
private void startStory() {
Intent intent = new Intent(this, StoryActivity.class);
startActivity(intent);
}
}
Terence Evans
1,870 PointsSorry. I have taken the code, pasted it to Word then copied it here. Hopefully it works:
import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;
public class MainActivity extends Activity {
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();
}
});
}
private void startStory() {
Intent intent = new Intent(this, StoryActivity.class);
startActivity(intent);
}
}
Jacob Bergdahl
29,119 PointsIt's hard to say just looking at the code you've provided. There are no real errors in this code, other than the fact that the variable "name" is assigned but never used.
Terence Evans
1,870 PointsI just tried it AGAIN and still nothing. I noticed that my "logcat" has 6 lines. I copy and paste them: 07-10 18:08:33.106 1085-1085/com.example.twesq.interactivestory D/dalvikvm﹕ GC_FOR_ALLOC freed 36K, 10% free 3206K/3528K, paused 86ms, total 87ms 07-10 18:08:33.306 1085-1085/com.example.twesq.interactivestory I/dalvikvm-heap﹕ Grow heap (frag case) to 8.555MB for 5400016-byte allocation 07-10 18:08:33.416 1085-1094/com.example.twesq.interactivestory D/dalvikvm﹕ GC_FOR_ALLOC freed <1K, 4% free 8479K/8804K, paused 104ms, total 104ms 07-10 18:08:34.776 1085-1085/com.example.twesq.interactivestory D/﹕ HostConnection::get() New Host Connection established 0xb72a8c98, tid 1085 07-10 18:08:34.866 1085-1085/com.example.twesq.interactivestory W/EGL_emulation﹕ eglSurfaceAttrib not implemented 07-10 18:08:34.876 1085-1085/com.example.twesq.interactivestory D/OpenGLRenderer﹕ Enabling debug mode 0
Does any of this help?
Terence Evans
1,870 PointsI also noticed that my memory usage jumps up to over 90% when I run it.
Jon Kussmann
Courses Plus Student 7,254 PointsHi Terence,
Could you post your activity_main.xml as well as your StoryActivity class?
Terence Evans
1,870 PointsSure. My activity_main.xml is: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/titleImageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:src="@drawable/main_title"
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:contentDescription="Signals from Mars"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START YOUR ADVENTURE"
android:id="@+id/startButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/nameEditText"
android:hint="Enter your name to begin"
android:maxLength="30"
android:layout_alignBottom="@+id/titleImageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
And my StoryActivity class is: package com.example.twesq.interactivestory;
import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem;
public class StoryActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.story, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thanks a bunch.
Jon Kussmann
Courses Plus Student 7,254 PointsCan you try something for me?
private void startStory() {
Intent intent = new Intent(this, StoryActivity.class);
startActivity(intent);
}
Can you change "this" to "MainActivity.this"?
If that doesn't work, I suggest just continuing with the course for a little while longer without testing that button for now to see if something 'clicks'
Jon Kussmann
Courses Plus Student 7,254 PointsJon Kussmann
Courses Plus Student 7,254 PointsGo ahead and try posting the code.