• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Frustrated Noob: Unable to open stack trace file error

peakfreak

Lurker
Hi all
As you will guess I am a complete noob to Android dev by the fact that my issue is with a hellow world application.
I am working my way through a tutorial on hackaday.com (can't post the link yet).
I have written my code without any compile errors but when I run the app in my emulator all I get is and error saying "The appliacation has stopped unexpectedly"
I have scoured the tinterweb and tried a few things all to no avail. Looking through the LogCat I am getting permission errors (amongst others I'm unsure of yet). I'm hoping you guys and gals out there can assist.
I'm using Eclipse, My AVD is 2.1 and the LogCat information is as follows.
TIA for any help
Bren

01-12 22:21:23.905: D/AndroidRuntime(350): Shutting down VM
01-12 22:21:23.905: W/dalvikvm(350): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
01-12 22:21:23.925: E/AndroidRuntime(350): Uncaught handler: thread main exiting due to uncaught exception
01-12 22:21:23.935: E/AndroidRuntime(350): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.peakfreak.improvedhelloworld/com.peakfreak.improvedhelloworld.ImprovedHelloWorldActivity}: java.lang.ClassCastException: android.widget.EditText
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.os.Handler.dispatchMessage(Handler.java:99)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.os.Looper.loop(Looper.java:123)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.main(ActivityThread.java:4363)
01-12 22:21:23.935: E/AndroidRuntime(350): at java.lang.reflect.Method.invokeNative(Native Method)
01-12 22:21:23.935: E/AndroidRuntime(350): at java.lang.reflect.Method.invoke(Method.java:521)
01-12 22:21:23.935: E/AndroidRuntime(350): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-12 22:21:23.935: E/AndroidRuntime(350): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-12 22:21:23.935: E/AndroidRuntime(350): at dalvik.system.NativeStart.main(Native Method)
01-12 22:21:23.935: E/AndroidRuntime(350): Caused by: java.lang.ClassCastException: android.widget.EditText
01-12 22:21:23.935: E/AndroidRuntime(350): at com.peakfreak.improvedhelloworld.ImprovedHelloWorldActivity.onCreate(ImprovedHelloWorldActivity.java:24)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
01-12 22:21:23.935: E/AndroidRuntime(350): ... 11 more
01-12 22:21:23.985: I/dalvikvm(350): threadid=7: reacting to signal 3
01-12 22:21:23.985: E/dalvikvm(350): Unable to open stack trace file '/data/anr/traces.txt': Permission denied
 
Code:
01-12 22:21:23.925: E/AndroidRuntime(350): Uncaught handler: thread main exiting due to uncaught exception
01-12 22:21:23.935: E/AndroidRuntime(350): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.peakfreak.improvedhelloworld/com.peakfreak.improvedhelloworld.ImprovedHelloWorldActivity}: java.lang.ClassCastException: android.widget.EditText
[COLOR="Gray"](...)[/COLOR]
[COLOR=RED]01-12 22:21:23.935: E/AndroidRuntime(350): Caused by: java.lang.ClassCastException: android.widget.EditText
01-12 22:21:23.935: E/AndroidRuntime(350): at com.peakfreak.improvedhelloworld.ImprovedHelloWorldActivity.onCreate(ImprovedHelloWorldActivity.java:24)[/COLOR]
[COLOR="Gray"](...)[/COLOR]
01-12 22:21:23.985: I/dalvikvm(350): threadid=7: reacting to signal 3
01-12 22:21:23.985: E/dalvikvm(350): Unable to open stack trace file '/data/anr/traces.txt': Permission denied

At line 24 of ImprovedHelloWorldActivity.java, you're trying to cast an android.widget.EditText into something it can't be cast into.

Can you post ImprovedHelloWorldActivity.java between [CODE] ... [/CODE] tags? And preferably, highlight line 24 in red.
 
At line 24 of ImprovedHelloWorldActivity.java, you're trying to cast an android.widget.EditText into something it can't be cast into.

Can you post ImprovedHelloWorldActivity.java between [CODE] ... [/CODE] tags? And preferably, highlight line 24 in red.

Hi jiminaus

Code below for the ImprovedHelloWorldActivity.java I have highlighted line 24 in red as it is within the Eclipse.
Code:
[SIZE=2][COLOR=#7f0055]

[B][SIZE=2][COLOR=#7f0055]package
[/COLOR][/SIZE][/B][/COLOR][/SIZE][LEFT][SIZE=2]com.peakfreak.improvedhelloworld;[/SIZE]
 
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.app.Activity;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.content.Context;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.os.Bundle;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View.OnClickListener;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.Button;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.EditText;[/SIZE]
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.Toast;[/SIZE]
 
[LEFT][SIZE=2] [/SIZE]
[SIZE=2] [/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
[/LEFT]
[/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] ImprovedHelloWorldActivity [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]extends[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] Activity {[/SIZE]
 
[LEFT][SIZE=2]EditText [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f5fbf]
[/COLOR][/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onCreate(Bundle savedInstanceState) {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
[SIZE=2]setContentView(R.layout.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]main[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Capture our button from layout[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2][COLOR=red]Button button = (Button)findViewById(R.id.[/COLOR][/LEFT]
[/LEFT]
[/SIZE][LEFT][I][SIZE=2][SIZE=2][COLOR=red]go[/COLOR][/SIZE][/SIZE][/I][SIZE=2][COLOR=red]);[/COLOR][/SIZE]
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Register the onClick listener with the implementation above[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][SIZE=2]button.setOnClickListener([/LEFT]
[/LEFT]
[/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mAddListener[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
[LEFT][SIZE=2]}[/SIZE][/LEFT]
 
[LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Create an anonymous implementation of OnClickListener[/COLOR][/SIZE]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]private[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mAddListener[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = [/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]new[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] OnClickListener()[/SIZE]
[SIZE=2]{[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]void[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] onClick(View v)[/SIZE]
[SIZE=2]{[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id = 0;[/SIZE]
[SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// do something when the button is clicked[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
[/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055]
[/COLOR][/SIZE][SIZE=2]{[/SIZE]
[SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] = (EditText)findViewById(R.id.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]);[/SIZE][/LEFT]
 
[LEFT][SIZE=2]Context context = getApplicationContext();[/SIZE]
[SIZE=2]CharSequence text = [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"Hello "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2].getText() + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"!"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] duration = Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_LONG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE][/LEFT]
 
[LEFT][SIZE=2]Toast toast = Toast.[I]makeText[/I](context, text, duration);[/SIZE]
[SIZE=2]toast.show();[/SIZE]
[SIZE=2]}[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Exception ex)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]Context context = getApplicationContext();[/SIZE]
[SIZE=2]CharSequence text = ex.toString() + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ID = "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + id;[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] duration = Toast.[/SIZE][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]LENGTH_LONG[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2];[/SIZE][/LEFT]
 
[LEFT][SIZE=2]Toast toast = Toast.[I]makeText[/I](context, text, duration);[/SIZE]
[SIZE=2]toast.show();[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]};[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
[/LEFT]
 
findViewById(R.id.go) is not finding a Button as you're expecting but is finding an EditText instead. Check your layout. Go into XML tab at the bottom. What element has android:id="@+id/go"? Post the whole layout if you're stuck.
 
After reading your first reply earlier jiminaus, I spotted my dopey mistake. It was as you say the naming of my layout items, I had the EditText and the Button names the wrong way round. I named them correctly but it still didn't work but I looked in R.java and saw that the references in there needed the 0 and 1 at the end of each reference changing also (see below highlighted in red). It's now working correctly and I have learned loads from what is a simple silly mistake :-)
Thanks very much for taking a look for me, a fresh pair of eyes always sees clearer.
Just as an aside, when I change anything in the layout (main.xml) is there any way to have Eclipse automatically rebuild the R.java file?

Code:
[LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]class[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id {[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]go[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]=0x7f05000[COLOR=red]1[/COLOR];[/SIZE]
[B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]static[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]final[/COLOR][/SIZE][/COLOR][/SIZE][/B][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]int[/COLOR][/SIZE][/COLOR][/SIZE][/B][I][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][/I][SIZE=2]=0x7f05000[COLOR=red]0[/COLOR];[/SIZE][/LEFT]
[SIZE=2]}[/SIZE]
 
Eclipse will rebuild R.java as part of building your app. If you change a layout, build your app and R.java will change.

That's an important point. Never manually change R.java. The whole file is recreated when your app is built. Any manual changes will be lost.

Also try to treat R.java as opaque. Don't concern yourself with its values. If something's wrong with the values in R.java, the problem is always elsewhere.

(And please post plain text code. The syntax highlighting your using is making the code harder to read, not easier.)
 
Back
Top Bottom