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 trialFarouk Charkas
1,957 PointsI have a method run() error!
I have written the following code below, but I have this error "JavaTester.java:123: error: variable response is already defined in method run()", anybody know how I can fix this? Thanks in advance!
// I have initialized a java.io.Console for you. It is in a variable named console.
String response;
do {
String response = console.readLine("Do you understand do while loops?");
if (response.equalsIgnoreCase("no")) {
}
} while (response.equalsIgnoreCase("no"));
6 Answers
Jon Kussmann
Courses Plus Student 7,254 PointsString response;
do {
response = console.readLine("Do you understand do while loops?");
if (response.equalsIgnoreCase("no")) {
}
} while (response.equalsIgnoreCase("no"));
You don't put "String" in front of the second "response" because is declaring a new variable called "response" which you already have, which is why you got the original error.
Jon Kussmann
Courses Plus Student 7,254 PointsHi Farouk,
Try deleting
String response;
In your very first line. Hope that helps. If not please let me know.
Farouk Charkas
1,957 PointsThat helped, but then I got those Bummer! thing from Treehouse, with the same code, but i get the error "Did you create a new String called response",
Farouk Charkas
1,957 Pointsreasonable.
Farouk Charkas
1,957 Pointsreasonable.
Farouk Charkas
1,957 Pointsreasonable.