Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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