Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android Build a Simple Android App Improving Our Code Using the New Colors

Luke Horvath
Luke Horvath
590 Points

App doesn't run after these changes. Code Included

01-01 04:05:10.960 10606-10606/? D/dalvikvm: Not late-enabling CheckJNI (already on)
01-01 04:05:11.860 10606-10606/com.example.phantom.funfacts E/Trace: error opening trace file: No such file or directory (2)
01-01 04:05:12.620 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.view.Window$Callback.onProvideKeyboardShortcuts, referenced from method android.support.v7.view.WindowCallbackWrapper.onProvideKeyboardShortcuts
01-01 04:05:12.630 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve interface method 21839: Landroid/view/Window$Callback;.onProvideKeyboardShortcuts (Ljava/util/List;Landroid/view/Menu;I)V
01-01 04:05:12.630 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-01 04:05:12.640 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to find class referenced in signature (Landroid/view/SearchEvent;)
01-01 04:05:12.640 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.view.Window$Callback.onSearchRequested, referenced from method android.support.v7.view.WindowCallbackWrapper.onSearchRequested
01-01 04:05:12.650 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve interface method 21841: Landroid/view/Window$Callback;.onSearchRequested (Landroid/view/SearchEvent;)Z
01-01 04:05:12.650 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-01 04:05:12.660 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.view.Window$Callback.onWindowStartingActionMode, referenced from method android.support.v7.view.WindowCallbackWrapper.onWindowStartingActionMode
01-01 04:05:12.660 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve interface method 21845: Landroid/view/Window$Callback;.onWindowStartingActionMode (Landroid/view/ActionMode$Callback;I)Landroid/view/ActionMode;
01-01 04:05:12.660 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x72 at 0x0002
01-01 04:05:12.670 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.content.res.TypedArray.getChangingConfigurations, referenced from method android.support.v7.widget.TintTypedArray.getChangingConfigurations
01-01 04:05:12.680 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve virtual method 494: Landroid/content/res/TypedArray;.getChangingConfigurations ()I
01-01 04:05:12.680 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 04:05:12.690 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.content.res.TypedArray.getType, referenced from method android.support.v7.widget.TintTypedArray.getType
01-01 04:05:12.700 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve virtual method 516: Landroid/content/res/TypedArray;.getType (I)I
01-01 04:05:12.700 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x6e at 0x0008
01-01 04:05:12.960 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.content.res.Resources.getDrawable, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawable
01-01 04:05:12.980 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve virtual method 457: Landroid/content/res/Resources;.getDrawable (ILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-01 04:05:12.980 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 04:05:12.990 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.content.res.Resources.getDrawableForDensity, referenced from method android.support.v7.widget.ResourcesWrapper.getDrawableForDensity
01-01 04:05:12.990 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve virtual method 459: Landroid/content/res/Resources;.getDrawableForDensity (IILandroid/content/res/Resources$Theme;)Landroid/graphics/drawable/Drawable;
01-01 04:05:12.990 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x6e at 0x0002
01-01 04:05:13.070 10606-10606/com.example.phantom.funfacts I/dalvikvm: Could not find method android.content.Context.getColorStateList, referenced from method android.support.v7.content.res.AppCompatResources.getColorStateList
01-01 04:05:13.100 10606-10606/com.example.phantom.funfacts W/dalvikvm: VFY: unable to resolve virtual method 308: Landroid/content/Context;.getColorStateList (I)Landroid/content/res/ColorStateList;
01-01 04:05:13.100 10606-10606/com.example.phantom.funfacts D/dalvikvm: VFY: replacing opcode 0x6e at 0x0006
01-01 04:05:13.360 10606-10606/com.example.phantom.funfacts D/AndroidRuntime: Shutting down VM
01-01 04:05:13.360 10606-10606/com.example.phantom.funfacts W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40ac4930)
01-01 04:05:13.390 10606-10606/com.example.phantom.funfacts E/AndroidRuntime: FATAL EXCEPTION: main
                                                                              java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phantom.funfacts/com.example.phantom.funfacts.Funfacts}: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.RelativeLayout
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
                                                                                  at android.app.ActivityThread.access$600(ActivityThread.java:141)
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                  at android.os.Looper.loop(Looper.java:137)
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5041)
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                  at java.lang.reflect.Method.invoke(Method.java:511)
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
                                                                                  at dalvik.system.NativeStart.main(Native Method)
                                                                               Caused by: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.RelativeLayout
                                                                                  at com.example.phantom.funfacts.Funfacts.onCreate(Funfacts.java:29)
                                                                                  at android.app.Activity.performCreate(Activity.java:5104)
                                                                                  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
                                                                                  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
                                                                                  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 
                                                                                  at android.app.ActivityThread.access$600(ActivityThread.java:141) 
                                                                                  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 
                                                                                  at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                                                  at android.os.Looper.loop(Looper.java:137) 
                                                                                  at android.app.ActivityThread.main(ActivityThread.java:5041) 
                                                                                  at java.lang.reflect.Method.invokeNative(Native Method) 
                                                                                  at java.lang.reflect.Method.invoke(Method.java:511) 
                                                                                  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 
                                                                                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 
                                                                                  at dalvik.system.NativeStart.main(Native Method) 
01-01 04:05:19.050 10606-10606/com.example.phantom.funfacts I/Process: Sending signal. PID: 10606 SIG: 9
Luke Horvath
Luke Horvath
590 Points

01-01 04:10:06.680 10856-10856/com.example.phantom.funfacts E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phantom.funfacts/com.example.phantom.funfacts.Funfacts}: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.RelativeLayout at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.RelativeLayout at com.example.phantom.funfacts.Funfacts.onCreate(Funfacts.java:29) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)  at android.app.ActivityThread.access$600(ActivityThread.java:141)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)  at android.os.Handler.dispatchMessage(Handler.java:99)  at android.os.Looper.loop(Looper.java:137)  at android.app.ActivityThread.main(ActivityThread.java:5041)  at java.lang.reflect.Method.invokeNative(Native Method)  at java.lang.reflect.Method.invoke(Method.java:511)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)  at dalvik.system.NativeStart.main(Native Method)

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Sorry about the late reply on this, but if you haven't gotten past this issue, check out this key line from that stack trace:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.phantom.funfacts/com.example.phantom.funfacts.Funfacts}: java.lang.ClassCastException: android.support.constraint.ConstraintLayout cannot be cast to android.widget.RelativeLayout

ClassCastException means that you are casting the wrong type of View in your code. Based on the ConstraintLayout and RelativeLayout listed in the details, it sounds like you declared a variable of type RelativeLayout but are then trying to get a ConstraintLayout from the layout file (which was probably created by default when you started the project). ConstraintLayouts are similar to RelativeLayouts but are newer to Android, and we talk about them a little more in the next project.

Luke Horvath
Luke Horvath
590 Points

Hey Ben. Thanks for getting back to me on this post too. I hadn't seen this when I wrote my reply to my most recent question.

The problem I was having when following the video; is that, I was working on the 2.3.1 Android Studio, where your lesson was being taught on the 1.5. The difference I noticed is that the newer version of Android Studio used a ConstraintLayout as a default field view. I changed the code and just carried on with the lessons as followed. Took me a while to work out but as my development learning is developing, I am starting to understand a lot and it all applies to itself within. I am looking forward to hearing your method to solve the getImageId() fault on my other question.

I appreciate all the help that you are providing :) Thanks

Ben Jakuben
Ben Jakuben
Treehouse Teacher

Sorry about the trouble with the version differences! Ben Deitch will be updating the Simple Android App course to use the latest tools after Google IO, which takes place next week. I'm glad you were able to work through the differences.

The next course in the track is Interactive Story, which I updated more recently to also use 2.3.1 and ConstraintLayout. Hope you enjoy it!