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 trialandrejtu7
6,649 PointsI 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")) { ^
1 Answer
Steve Hunter
57,712 PointsHi 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
1,957 PointsSteve Hunter is correct, just supporting.
Steve Hunter
57,712 PointsThat 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
1,957 PointsNo problem, you had the right answer, @andrejtu7 got the problem solved so after all it does not.
andrejtu7
6,649 Pointsandrejtu7
6,649 Points