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

Android Build a Simple Android App with Kotlin Improving Our Code Adding Colors

Alina Pohl
Alina Pohl
5,089 Points

Set the text color of foodLabel to Color.BLUE. Then set the text color of drinkLabel to Color.GRAY. Doesn't Work, Help

I don't know what's wrong, can somebody find the mistake and help me?

import android.app.Activity import android.os.Bundle import android.widget.TextView import android.widget.RelativeLayout

class MealActivity : Activity() { override fun onCreate(savedInstanceState: Bundle) { super.onCreate(savedInstanceState)

setContentView(R.layout.activity_meal)

val foodLabel = findViewById(R.id.foodTextView) as TextView
val drinkLabel = findViewById(R.id.drinkTextView) as TextView
val mealLayout = findViewById(R.id.mealLayout) as RelativeLayout
mealLayout.backgroundColor = Color.RED

foodLabel.setTextColor(Color.BLUE)
drinkLabel.setTextColor(Color.GRAY)

} }

I always get this error: MealActivity.kt:17:15: error: unresolved reference: setTextColor foodLabel.setTextColor(Color.BLUE) ^ MealActivity.kt:18:16: error: unresolved reference: setTextColor drinkLabel.setTextColor(Color.GRAY)

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Alina Pohl ! It looks to me like you're doing pretty well. The biggest hint in this challenge is this line:

mealLayout.backgroundColor = Color.RED

Your two lines that set the textColor should be almost identical including the use of an equals sign as opposed to a pair of parentheses. In this line, they are setting the backgroundColor. Note that it does not use the word "set" as you have in your code. Instead, it just says backgroundColor. We're looking for the same thing here except with textColor instead of backgroundColor.

I feel like you can get it with these hints, but let me know if you're still stuck! :sparkles:

Alina Pohl
Alina Pohl
5,089 Points

Thanks, it worked!