Football Fans: Download the 2012 Schedule App from Google Play!


Go Back   Android Forums > Android Development > Application Development > Developer 101

Developer 101 101 Tutorials



Reply
 
LinkBack Thread Tools
Old January 12th, 2012, 04:31 PM   #1 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 3
 
Device(s):
Thanks: 2
Thanked 0 Times in 0 Posts
Default Frustrated Noob: Unable to open stack trace file error

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.ImprovedHelloWorl dActivity}: java.lang.ClassCastException: android.widget.EditText
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.java:2496)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.handleLaunchActivity(Ac tivityThread.java:2512)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.access$2200(ActivityThr ead.java:119)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread$H.handleMessage(Activit yThread.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.jav a: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$MethodAndArgsCa ller.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.ImprovedHelloWorl dActivity.onCreate(ImprovedHelloWorldActivity.java :24)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.Instrumentation.callActivityOnCreate(I nstrumentation.java:1047)
01-12 22:21:23.935: E/AndroidRuntime(350): at android.app.ActivityThread.performLaunchActivity(A ctivityThread.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

peakfreak is offline  
Reply With Quote
Sponsors
Old January 13th, 2012, 04:12 AM   #2 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

Quote:
Originally Posted by peakfreak View Post
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
(...)
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.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.
jiminaus is offline  
Reply With Quote
Old January 13th, 2012, 08:15 AM   #3 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 3
 
Device(s):
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by jiminaus View Post
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:


package
com.peakfreak.improvedhelloworld;
import
android.app.Activity;
import
android.content.Context;
import
android.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.Toast;
    public
class ImprovedHelloWorldActivity extends Activity {
EditText helloName; /** Called when the activity is first created. */ @Override publicvoid onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
//Capture our button from layout Button button = (Button)findViewById(R.id.
go);
//Register the onClick listener with the implementation above button.setOnClickListener(
mAddListener);
}
// Create an anonymous implementation of OnClickListener private OnClickListener mAddListener = new OnClickListener() { publicvoid onClick(View v) { long id = 0; // do something when the button is clicked try { helloName = (EditText)findViewById(R.id.helloName);
Context context = getApplicationContext(); CharSequence text = "Hello " + helloName.getText() + "!"; int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration); toast.show(); } catch (Exception ex) { Context context = getApplicationContext(); CharSequence text = ex.toString() + "ID = " + id; int duration = Toast.LENGTH_LONG;
Toast toast = Toast.makeText(context, text, duration); toast.show(); } } };
}

peakfreak is offline  
Reply With Quote
Old January 13th, 2012, 03:43 PM   #4 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

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.
jiminaus is offline  
Reply With Quote
The Following User Says Thank You to jiminaus For This Useful Post:
peakfreak (January 13th, 2012)
Old January 13th, 2012, 04:19 PM   #5 (permalink)
New Member
 
Join Date: Mar 2011
Posts: 3
 
Device(s):
Thanks: 2
Thanked 0 Times in 0 Posts
Default

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:
publicstaticfinalclass id { publicstaticfinalintgo=0x7f050001; publicstaticfinalinthelloName=0x7f050000;
}
peakfreak is offline  
Reply With Quote
Old January 13th, 2012, 04:26 PM   #6 (permalink)
Premium Member
 
Join Date: Oct 2011
Location: Sydney, Australia
Posts: 193
 
Device(s): Galaxy Nexus GSM
Thanks: 2
Thanked 37 Times in 33 Posts
Default

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.)
jiminaus is offline  
Last edited by jiminaus; January 13th, 2012 at 04:29 PM.
Reply With Quote
The Following User Says Thank You to jiminaus For This Useful Post:
peakfreak (January 13th, 2012)
Reply

Bookmarks


Go Back   Android Forums > Android Development > Application Development > Developer 101 User CP
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -5. The time now is 08:22 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Custom vBulletin Skins by: Relivo