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!

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

Android Build a Simple Android App with Kotlin Improving Our Code Dynamically Changing the Background Color

samuel zaffran
samuel zaffran
24,815 Points

Mistake in the challenge

Hi, It's look like there is a mistake in the challenge cause i tried different ways but i still have this result in the bummer : MealActivity.kt:13:55: error: unresolved reference: RelativeLayout val mealLayout = findViewById(R.id.mealLayout) as RelativeLayout

2 Answers

Ben Deitch
Ben Deitch
Treehouse Teacher

Hey Samuel, good catch! It looks like that code challenge is missing an import statement for RelativeLayout. I've added it back in. If you refresh the page or just add this bit to the top, import android.widget.RelativeLayout, you should be good to go :)

Boban Talevski
Boban Talevski
24,793 Points

This either wasn't enough to fix the challenge, or I'm still struggling with Kotlin syntax :). Cause all I'm doing is adding this line


and I'm getting this message: Bummer! MealActivity.kt:15:18: error: unresolved reference: setBackgroundColor mealLayout!!.setBackgroundColor(Color.GREEN)

Tried without !! as it doesn't seem we need it (shouldn't be null anyway?), tried adding semicolon at the end of the line and it still doesn't work. Am I missing something or there's still a problem with this challenge? Has anyone managed to complete it and how?

EDIT: Well, the answer was in the next challenge and the line should be

mealLayout.backgroundColor = Color.GREEN

Funny thing is, this doesn't seem to work in Android Studio when trying to set the background color of the layout in our app, at least in version 2.3. I'm keeping it as a ConstraintLayout though, haven't changed it to RelativeLayout as in the videos, not sure if that might have anything to do with it.

Mine is set as a RelativeLayout, and it's not working for me either. I tested it after getting it wrong in the Challenge (I used SetBackgroundColor() too), and it's not working. Also tried without the "!!", but no luck.