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

How to set the text color of foodLabel to Color.BLUE and then set the text color of drinkLabel to Color.GRAY.

Hi, I need help to pass this Challenge Task 1 of 1.

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

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.text.setTextColor(Color.BLUE); findViewById(R.id.foodTextView);
    drinkLabel.text.setTextColor(Color.GRAY); findViewById(R.id.drinkTextView);
    RelativeLayout mealLayout = (RelativeLayout) findViewById(R.id.mealLayout);
    mealLayout.setBackgroundColor(Color.GREEN);
}

}

It shows 2 errors

./MealActivity.java:11: cannot find symbol symbol : variable text location: class TextView foodLabel.text.setTextColor(Color.BLUE); findViewById(R.id.foodTextView); ^ ./MealActivity.java:12: cannot find symbol symbol : variable text location: class TextView drinkLabel.text.setTextColor(Color.GRAY); findViewById(R.id.drinkTextView); ^ 2 errors

Thanks in advance.

2 Answers

Hi Beau,

What you've written is correct just that there is no need to add the .text . Also write the new code after mealLayout.setBackgroundColor(Color.GREEN); this line

So instead of
foodLabel.text.setTextColor(Color.BLUE);
drinkLabel.text.setTextColor(Color.GRAY);

it should have been

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

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);

        // Add here
        foodLabel.setTextColor(Color.BLUE);
       drinkLabel.setTextColor(Color.GRAY);  
    }
}

Hope this helps

luke moloney
luke moloney
2,347 Points

Thx Gunjeet Hattar!!!

Hi Gunjeet, You are an Angel. Thank you very much and the code worked...

Glad it worked.