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 trial

General Discussion

Crystal ball app errors someone please tell me what is going on

05-13 08:02:04.910: D/AndroidRuntime(915): Shutting down VM 05-13 08:02:04.910: W/dalvikvm(915): threadid=1: thread exiting with uncaught exception (group=0xb4ad3ba8) 05-13 08:02:04.930: E/AndroidRuntime(915): FATAL EXCEPTION: main 05-13 08:02:04.930: E/AndroidRuntime(915): Process: com.example.crystalball2, PID: 915 05-13 08:02:04.930: E/AndroidRuntime(915): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.crystalball2/com.example.crystalball2.MainActivity}: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread.access$800(ActivityThread.java:135) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.os.Handler.dispatchMessage(Handler.java:102) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.os.Looper.loop(Looper.java:136) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread.main(ActivityThread.java:5017) 05-13 08:02:04.930: E/AndroidRuntime(915): at java.lang.reflect.Method.invokeNative(Native Method) 05-13 08:02:04.930: E/AndroidRuntime(915): at java.lang.reflect.Method.invoke(Method.java:515) 05-13 08:02:04.930: E/AndroidRuntime(915): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 05-13 08:02:04.930: E/AndroidRuntime(915): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 05-13 08:02:04.930: E/AndroidRuntime(915): at dalvik.system.NativeStart.main(Native Method) 05-13 08:02:04.930: E/AndroidRuntime(915): Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button 05-13 08:02:04.930: E/AndroidRuntime(915): at com.example.crystalball2.MainActivity.onCreate(MainActivity.java:21) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.Activity.performCreate(Activity.java:5231) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 05-13 08:02:04.930: E/AndroidRuntime(915): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159) 05-13 08:02:04.930: E/AndroidRuntime(915): ... 11 more

1 Answer

What does your code look like?

This exception may be your problem: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.Button

When creating objects make sure that you are using the right casts, and that if you are creating a Button object with findViewById that you are passing in the correct ID.

Example: Button myButton = (Button) findViewById( /* make sure this isn't a TextView */ );

Hope this helps.

Also - if you post these in the android forum more people will be able to see it and respond to help you :)