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 trialhakan Gülay
8,489 PointsUnfortunately Interactive Story has Stopped
it gives me an error and ı cant not run it.
package com.example.hakan.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.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.widget.Button; import android.widget.ImageView; import android.widget.TextView; import android.app.Activity; import android.graphics.drawable.Drawable;
import com.example.hakan.interactivestory.R; import com.example.hakan.interactivestory.model.Story; import com.example.hakan.interactivestory.model.page;
public class StoryActivity extends Activity {
public static final String TAG = StoryActivity.class.getSimpleName();
private Story mStory = new Story();
private TextView mTextView;
private ImageView mImageView;
private Button mChoise1;
private Button mChoise2;
private String mName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_story4);
Intent intent = getIntent();
mName = intent.getStringExtra(getString(R.string.key_name));
if (mName == null){
mName = "Friend";
}
Log.d(TAG, mName);
mTextView = (TextView) findViewById(R.id.storyTextView);
mImageView = (ImageView) findViewById(R.id.storyImageView);
mChoise1 = (Button) findViewById(R.id.choiseButton1);
mChoise2 = (Button) findViewById(R.id.choiseButton2);
}
private void loadPage(){
page Page = mStory.getPage(0);
Drawable drawable = ResourcesCompat.getDrawable(getResources(), Page.getImageId(), null);
mImageView.setImageDrawable(drawable);
String pageText = Page.getText();
pageText = String.format(pageText,mName);
mTextView.setText(Page.getText());
mChoise1.setText(Page.getChoice1().getText());
mChoise2.setText(Page.getChoice2().getText());
}
}
here is logCat
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1880) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) 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:787) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.NullPointerException at com.example.hakan.interactivestory.model.Story.<init>(Story.java:13) at com.example.hakan.interactivestory.ui.StoryActivity.<init>(StoryActivity.java:26) at java.lang.Class.newInstanceImpl(Native Method) at java.lang.Class.newInstance(Class.java:1319) at android.app.Instrumentation.newActivity(Instrumentation.java:1023) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1871) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) at android.app.ActivityThread.access$600(ActivityThread.java:123) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4424) 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:787) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554) at dalvik.system.NativeStart.main(Native Method)
Seth Kroger
56,413 PointsSeth Kroger
56,413 PointsThis looks like the relevant part of the logcat: "Caused by: java.lang.NullPointerException at com.example.hakan.interactivestory.model.Story.<init>(Story.java:13)". The the problem is happening in Story.jav a at line 13.