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

Challenge Task 1 of 1 Let's continue to add color to MealActivity. In the onCreate() method, set the te

Let's continue to add color to MealActivity. In the onCreate() method, set the text color of foodLabel to Color.BLUE. Then set the text color of drinkLabel to Color.GRAY.

Getting this error Bummer: MealActivity.kt:16:1: error: assignments are not expressions, and only expressions are allowed in this context foodLabel.TextView = Color.BLUE. ^ MealActivity.kt:16:11: error: unresolved reference: TextView foodLabel.TextView = Color.BLUE. ^ MealActivity.kt:17:5: error: unresolved reference: drinkLabel drinkLabel.TextView = Color.GRAY
MealActivity.kt

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.TextView = Color.BLUE. drinkLabel.TextView = Color.GRAY } }

MealActivity.kt
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.TextView = Color.BLUE.
    drinkLabel.TextView = Color.GRAY
  }
}

3 Answers

Karen Fletcher
Karen Fletcher
19,189 Points

Much like the mealLayout.backgroundColor = Color.RED is setting the color of the background of the RecyclerView, you want to set the color of the text for the foodLabel and drinkLabel TextViews. Try using .textColor instead. And double check the extra dot you have after Color.BLUE, otherwise the compiler will be looking for another call to chain.

Thank you Karen :)

thanh van giang
thanh van giang
376 Points

hi, my code is wrong and I don't know why! Please help me out!

public class MealActivity extends Activity {

public TextView foodLabel;
public TextView drinkLabel;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_meal);

    foodLabel = (TextView) findViewById(R.id.foodTextView);
    drinkLabel = (TextView) findViewById(R.id.drinkTextView);
    RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
    mealLayout.setBackgroundColor(Color.GREEN);
    foodLabel.setTextColor(Color.BLUE);
    drinkLabel.setTextColoe(Color.GRAY);
}

}

thanh van giang
thanh van giang
376 Points

oh I got it! Typo "Coloe", should be Color!