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 (2014) Improving Our Code Adding More Colors

Keishi Mii
Keishi Mii
3,122 Points

App keeps crashing after the step where the background should be switching colors randomly

I have followed the video exactly, but when I try to run the app it will just force exit the application instead of switching colors.

2 Answers


Can you please post the code of the activity which is causing the application crash as well as some logcat output?


Martin Georgiev
Martin Georgiev
13,541 Points


I have the same issue as well. After adding an Id to the RelativeLayout and trying to change it dynamically my app crashes. I receive the following error: "Caused by: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.RelativeLayout" showing the error on line 23 where I have: final RelativeLayout relativeLay = (RelativeLayout) findViewById(R.id.relativeLay);

I double-checked the code provided by the tutorial and what I have, Id, classes, methods etc...

update: I moved back several steps and tried to run the app without any color related code. It turns out that as soon as I put an ID on the RelaviteLayout the app crashes.