Unquote Game(JAVA), Cumulative Project 4, "variable firstQuestion is already defined in method" error

Link to where I am at
withdrawn by author
I am confused to why I am getting an error message, I am doing task #7 in Unquote, Cumulative Project 4 and it reads:

7. Some copy & paste.

The last three lines of startNewGame() (your setup method) should be as follows:

Question firstQuestion = chooseNewQuestion();
// displayQuestion(firstQuestion);
// displayQuestionsRemaining(questions.size());
The three methods you call (chooseNewQuestion(), displayQuestion(), and displayQuestionsRemaining()) do not exist, and so the bottom two lines are commented.

You will implement the first method, chooseNewQuestion(), in the next step, but the last two rely on Android APIs that you cannot yet use.

Eventually, you will un-comment this code and use the first method to present the question on-screen and the second to update the number of remaining questions.

This is my code for the startNewGame( ) Method and so fourth:

    void startNewGame() {
      Question firstQuestion = new Question(921238, "How tall is the Eiffel tower?", "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);
      Question secondQuestion = new Question(107343, "Who invented the computer algorithm?", "Charles Babbage", "John Carmack", "Alan Turing", "Ada Lovelace", 3);
      Question thirdQuestion = new Question(748294, "What is the name for the patch of skin found on your elbow?", "Elbow Skin", "Fascia Elbora", "Wenis", "Todd", 2);
      questions = new ArrayList<>();
      questions.add(firstQuestion);
      questions.add(secondQuestion);
      questions.add(thirdQuestion);
      totalCorrect = 0;
      totalQuestions = questions.size();
      Question firstQuestion = chooseNewQuestion();
      //displayQuestion(firstQuestion);
      //displayQuestionsRemaining(questions.size());
    }
    // TODO #4 add chooseNewQuestion() here:
    Question chooseNewQuestion() {
      int randomNum = generateRandomNumber(2);
      currentQuestionIndex = randomNum;
      return questions.get(currentQuestionIndex);

    }

When I run my code I get this:

MainActivity.java:24: error: variable firstQuestion is already defined in method startNewGame()
      Question firstQuestion = chooseNewQuestion();
               ^
1 error

I dont understand what is happening, I continued on to the next step where we/I defined the chooseNewQuestion( ) method as you can see in my code but the same problem still persists, please help. Should I just name my question objects differently? Idk.

1 Like
    void startNewGame() {
      Question firstQuestion = new Question(921238, "How tall is the Eiffel tower?", "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);

      Question firstQuestion = chooseNewQuestion();

    }

I think the error is referring to this. It’s been a minute since I’ve done Java so I could be wrong.

Yes, indeed I see that the error is referring to that specifically, though I dont know how to fix it.
I have seen others do it like this…

void startNewGame() {
      Question question1= new Question(921238, "How tall is the Eiffel tower?", "1024 ft", "1063 ft", "1124 ft", "1163 ft", 1);
      Question question2= new Question(107343, "Who invented the computer algorithm?", "Charles Babbage", "John Carmack", "Alan Turing", "Ada Lovelace", 3);
      Question question3= new Question(748294, "What is the name for the patch of skin found on your elbow?", "Elbow Skin", "Fascia Elbora", "Wenis", "Todd", 2);
      questions = new ArrayList<>();
      questions.add(firstQuestion);
      questions.add(secondQuestion);
      questions.add(thirdQuestion);
      totalCorrect = 0;
      totalQuestions = questions.size();
      Question firstQuestion = chooseNewQuestion();
      //displayQuestion(firstQuestion);
      //displayQuestionsRemaining(questions.size());
    }

so what I did right there is change the name of my question objects from firstQuestion to question1 and so on and so fourth, so the line where it indicates the error which is for Question firstQuestion = chooseNewQuestion(); doesnt happen anymore (eliminating the error) but idk if that is gonna cause problems in the future but if anyone else doesnt give me another suggestion then I guess I’ll just try it that way.

1 Like

As long as you keep track of what every value is, I don’t see it being a problem (unless it’s validator specific, I’m guessing this is one of those self-progress projects – I don’t have a pro account so I can’t see).