hangman | Sololearn: Learn to code for FREE!

0

hangman

what does the error mean and how can i fix my code: https://code.sololearn.com/c146a4M3tGde

9/29/2020 3:09:46 PM

Yahel

13 Answers

New Answer

0

static String secretWord ; //assign something like this, => empty atleast => =""; otherwise this next one cause error... static char[] lettersOfSecretWord = secretWord.toCharArray();

+1

Can you say what are trying with that code...?

+1

Remove this from the function takeUserinput() and add it before function at class level after ArrayList declaration.. Scanner scan = new Scanner(System.in);

+1

You have space initially to static String secretWord = " "; Make it to static String secretWord = "";

+1

Yes. Good one.. Do add description next time to get quick response if you want...!! You're welcome....

0

ok thanks!

0

but my program still has a problem and its not working well. why is that?

0

but if i do that it wont ask from the user to put input in after the first time. i put it in the method because at the last method - it loops it so it asks for input again and again.

0

yahel you can only create a single instance for Scanner class. If you put in that method it will not create again in 2nd call of that method, and previous object will not available.. You shloud make it static or class level object.. So it will available entire class and all the methods.. Show your update code.. As you said you may taking out user input function of scan.next(); but I said only take out Scanner object creation statement... It works, I tested..

0

https://code.sololearn.com/c146a4M3tGde so whats the problem now?

0

You are not calling randomWord(); any where.. So secretWord is not changing its value never.. And add these line after secure Word changing.. lettersOfSecretWord = secretWord.toCharArray(); System.out.println(secretWord) ; It's wotlrking without errors.. For correct output, Pls descriptions..

0

Thanks! but one last thing, run the game and see that i have an extra char at the start of the hidden word. how can i fix it? https://code.sololearn.com/c146a4M3tGde

0

oh, my bad... thank you! the whole code is good now!