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 (retired 2014) Getting Started with Android Java Variables Explained

I can't do Challenge task 1 of Getting Started with Andriod

OK, I've tried typing this:

favoriteColor String ; favoriteColor = "orange"; favoriteColor myName = "orange";
String = "My favourite colour is favoriteColor";

But the preview says that it can't find the 'symbol' for favoriteColor (in my case, my favourite colour is orange, just saying that in case it helps). How do I create this symbol, if I even need to?

1 Answer

"symbol" means "variable". It can't find the variable because your declarations are not correct. You declare a variable like this:

String myVariable;           // This line creates the variable (i.e. symbol)
myVariable = "hello";       // This line assigns the variable a value

You can also do the declaration and assignment on the same line:

String myVariable = "hello";        // This line declares the variable and assigns a value to it

You can't assign a value to a variable before it is declared, nor can you declare a variable with some variable type that doesn't exist.

// This doesn't work because myVariable has to be declared either before it is given a value of at the same time as it is given a value
myVariable = "hello";
String myVariable;

// This doesn't work because someKindOfVariable isn't a valid type (valid types are String, int, float, etc.)
someKindOfVariable myVariable = "hello";

You should only have one or two lines of code for this challenge (depending on whether you assign the variable a value in the same line where you declare it).