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 an Interactive Story App (Retired) User Input Getting Text from an EditText

I dont now what is wrong in my code I always get this error!? Can someone help me? Thanks

JavaTester.java:79: error: variable petName might not have been initialized if (petName.equalsIgnoreCase("ROVER")) { ^

EditText petNameField = (EditText)findViewById(R.id.petNameField);
String petName;petNameField.getText().toString();

1 Answer

Hi there,

Can you post the whole code please?

The error is saying that the variable petName has not been initialized. The code you have posted confirms that - there is nothing assigning a value to the variable. Should the second line you have posted be:

String petName = petNameField.getText().toString();

Using that, the value of the petNameField EditText is assigned to the variable.

I hope that helps - if not, shout back and I'll look into it further.

Steve.

Farouk Charkas
Farouk Charkas
1,957 Points

Steve Hunter is correct, just supporting.

That might have been me, Farouk. I wasn't paying attention when I clicked through to edit my answer and I think I might have inadvertently deleted either a comment or another answer. Apologies if I did - I'll have to pay more attention rather than trying to do a million things at once.

Apologies!

Steve.

Farouk Charkas
Farouk Charkas
1,957 Points

No problem, you had the right answer, @andrejtu7 got the problem solved so after all it does not.