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 trialzagros baban
1,288 PointsApp crashed android interactive story app
https://gyazo.com/82bb03735b57703265b5f3f664dcd6f7
when I add this code my app is crashed choice1Button.setText(page.getChoice1().getTextId()); choice2Button.setText(page.getChoice2().getTextId());
zagros baban
1,288 Pointshttps://gyazo.com/64eb16164af9f031a0f3333103e8cb08
08-15 02:54:45.977 4745-4745/com.example.interactivestory E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.interactivestory, PID: 4745 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.interactivestory/com.example.interactivestory.ui.StoryActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1 at android.content.res.Resources.getText(Resources.java:312) at android.content.res.Resources.getString(Resources.java:400) at android.content.Context.getString(Context.java:409) at com.example.interactivestory.ui.StoryActivity.loadPage(StoryActivity.java:66) at com.example.interactivestory.ui.StoryActivity.onCreate(StoryActivity.java:50) at android.app.Activity.performCreate(Activity.java:6237) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) at android.app.ActivityThread.-wrap11(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5417) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 08-15 02:54:46.381 1982-4464/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008cdf 08-15 02:54:46.382 1982-4464/system_process E/eglCodecCommon: glUtilsParamSize: unknow param 0x00008824
1 Answer
Lauren Moineau
9,483 PointsHi. If you look at the
Caused by
part of the log, it tells you:
- why the app crashed:
E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.interactivestory, PID: 4745 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.interactivestory/com.example.interactivestory.ui.StoryActivity}: android.content.res.Resources$NotFoundException: String resource ID #0x1
You want to remember ResourcesNotFoundException: String resource ID #0x1
here
- and where the problem is:
After
Caused by
, check the last blue link to your code and work your way up from there to understand what's happening. Let's go though the chain of methods that are called.
at com.example.interactivestory.ui.StoryActivity.onCreate(StoryActivity.java:50)
Click on the link. You're taken to your StoryActivity
class, in the onCreate()
method, line 50. I suppose it is where loadPage()
is called.
at com.example.interactivestory.ui.StoryActivity.loadPage(StoryActivity.java:66)
That second blue link will take you to line 66 of your StoryActivity
class, inside your loadPage()
method. I assume it's where
String pageText = getString(page.getTextId())
is called.
at android.content.Context.getString(Context.java:409)
On that line #66, Context.getString(resId)
is called
at android.content.res.Resources.getString(Resources.java:400)
This calls getResources().getString(resId)
at android.content.res.Resources.getText(Resources.java:312)
Which in turn calls getText(id).toString()
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
The system tries to call Resources.getText(id)
but cannot find the id, so it throws a NotFoundException("String resource ID #01")
. The problem is here, that resource is missing.
Start by checking your Story
class and make sure all your pages are set up properly there, meaning you have all pages numbered 0 to 6, and 2 choices for each page 0 to 4 set up.
Then check your strings.xml
file and make sure all these choice strings are listed there.
Chances are, you're missing some. Good luck!
Hope that helps :)
Lauren Moineau
9,483 PointsLauren Moineau
9,483 PointsHi. Could you copy/paste the content of your logcat please? (Showing just the Error log, using the filter). That would help. Thanks