1. Download our Official Android App: Forums for Android!

Apps Frustrated Noob: Unable to open stack trace file error

Discussion in 'Android Development' started by peakfreak, Jan 12, 2012.

  1. peakfreak

    peakfreak Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 21, 2011

    Mar 21, 2011
    4
    0
    5
    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
     

    Advertisement

  2. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    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.
     
  3. peakfreak

    peakfreak Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 21, 2011

    Mar 21, 2011
    4
    0
    5
    Hi jiminaus

    Code below for the ImprovedHelloWorldActivity.java I have highlighted line 24 in red as it is within the Eclipse.
    Code (Text):
    1. [SIZE=2][COLOR=#7f0055]
    2.  
    3. [B][SIZE=2][COLOR=#7f0055]package
    4. [/COLOR][/SIZE][/B][/COLOR][/SIZE][LEFT][SIZE=2]com.peakfreak.improvedhelloworld;[/SIZE]
    5.  
    6. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    7. [/LEFT]
    8. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.app.Activity;[/SIZE]
    9. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    10. [/LEFT]
    11. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.content.Context;[/SIZE]
    12. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    13. [/LEFT]
    14. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.os.Bundle;[/SIZE]
    15. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    16. [/LEFT]
    17. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View;[/SIZE]
    18. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    19. [/LEFT]
    20. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.view.View.OnClickListener;[/SIZE]
    21. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    22. [/LEFT]
    23. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.Button;[/SIZE]
    24. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    25. [/LEFT]
    26. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.EditText;[/SIZE]
    27. [LEFT][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]import[/LEFT]
    28. [/LEFT]
    29. [/COLOR][/SIZE][/COLOR][/SIZE][/B][LEFT][SIZE=2]android.widget.Toast;[/SIZE]
    30.  
    31. [LEFT][SIZE=2] [/SIZE]
    32. [SIZE=2] [/SIZE]
    33. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]public[/LEFT]
    34. [/LEFT]
    35. [/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]
    36.  
    37. [LEFT][SIZE=2]EditText [/SIZE][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]helloName[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];[/SIZE]
    38. [SIZE=2][COLOR=#3f5fbf][SIZE=2][COLOR=#3f5fbf]/** Called when the activity is first created. */[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f5fbf]
    39. [/COLOR][/SIZE][SIZE=2][COLOR=#646464][SIZE=2][COLOR=#646464]@Override[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#646464]
    40. [/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]
    41. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]super[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2].onCreate(savedInstanceState);[/SIZE]
    42. [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]
    43.  
    44. [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]//Capture our button from layout[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
    45. [/COLOR][/SIZE][SIZE=2][COLOR=red]Button button = (Button)findViewById(R.id.[/COLOR][/LEFT]
    46. [/LEFT]
    47. [/SIZE][LEFT][I][SIZE=2][SIZE=2][COLOR=red]go[/COLOR][/SIZE][/SIZE][/I][SIZE=2][COLOR=red]);[/COLOR][/SIZE]
    48. [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]
    49. [/COLOR][/SIZE][SIZE=2]button.setOnClickListener([/LEFT]
    50. [/LEFT]
    51. [/SIZE][LEFT][SIZE=2][COLOR=#0000c0][SIZE=2][COLOR=#0000c0]mAddListener[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);[/SIZE]
    52. [LEFT][SIZE=2]}[/SIZE][/LEFT]
    53.  
    54. [LEFT][SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// Create an anonymous implementation of OnClickListener[/COLOR][/SIZE]
    55. [/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]
    56. [SIZE=2]{[/SIZE]
    57. [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]
    58. [SIZE=2]{[/SIZE]
    59. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]long[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] id = 0;[/SIZE]
    60. [SIZE=2][COLOR=#3f7f5f][SIZE=2][COLOR=#3f7f5f]// do something when the button is clicked[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#3f7f5f]
    61. [/COLOR][/SIZE][B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]try[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2][COLOR=#7f0055]
    62. [/COLOR][/SIZE][SIZE=2]{[/SIZE]
    63. [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]
    64.  
    65. [LEFT][SIZE=2]Context context = getApplicationContext();[/SIZE]
    66. [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]
    67. [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]
    68.  
    69. [LEFT][SIZE=2]Toast toast = Toast.[I]makeText[/I](context, text, duration);[/SIZE]
    70. [SIZE=2]toast.show();[/SIZE]
    71. [SIZE=2]}[/SIZE]
    72. [B][SIZE=2][COLOR=#7f0055][SIZE=2][COLOR=#7f0055]catch[/COLOR][/SIZE][/COLOR][/SIZE][/B][SIZE=2] (Exception ex)[/SIZE]
    73. [SIZE=2]{[/SIZE]
    74. [SIZE=2]Context context = getApplicationContext();[/SIZE]
    75. [SIZE=2]CharSequence text = ex.toString() + [/SIZE][SIZE=2][COLOR=#2a00ff][SIZE=2][COLOR=#2a00ff]"ID = "[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] + id;[/SIZE]
    76. [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]
    77.  
    78. [LEFT][SIZE=2]Toast toast = Toast.[I]makeText[/I](context, text, duration);[/SIZE]
    79. [SIZE=2]toast.show();[/SIZE]
    80. [SIZE=2]}[/SIZE]
    81. [SIZE=2]}[/SIZE]
    82. [SIZE=2]};[/SIZE][/LEFT]
    83. [SIZE=2]}[/SIZE]
    84.  
    [/LEFT]
     
  4. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    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.
     
    peakfreak likes this.
  5. peakfreak

    peakfreak Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    4
    Joined:
    Mar 21, 2011

    Mar 21, 2011
    4
    0
    5
    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 (Text):
    1.  
    2. [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]
    3. [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]
    4. [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]
    5. [SIZE=2]}[/SIZE]
    6.  
     
  6. jiminaus

    jiminaus Well-Known Member
    Rank:
    None
    Points:
    63
    Posts:
    190
    Joined:
    Oct 27, 2011

    Oct 27, 2011
    190
    36
    63
    Sydney, Australia
    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.)
     
    peakfreak likes this.

Share This Page

Loading...