0

hangman

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

29th Sep 2020, 3:09 PM
Yahel
Yahel - avatar
13 ответов
0
static String secretWord ; //assign something like this, => empty atleast => =""; otherwise this next one cause error... static char[] lettersOfSecretWord = secretWord.toCharArray();
29th Sep 2020, 3:25 PM
Jayakrishna 🇮🇳
+ 1
Can you say what are trying with that code...?
29th Sep 2020, 5:21 PM
Jayakrishna 🇮🇳
+ 1
Remove this from the function takeUserinput() and add it before function at class level after ArrayList declaration.. Scanner scan = new Scanner(System.in);
29th Sep 2020, 5:35 PM
Jayakrishna 🇮🇳
+ 1
You have space initially to static String secretWord = " "; Make it to static String secretWord = "";
30th Sep 2020, 4:38 PM
Jayakrishna 🇮🇳
+ 1
Yes. Good one.. Do add description next time to get quick response if you want...!! You're welcome....
30th Sep 2020, 4:41 PM
Jayakrishna 🇮🇳
0
ok thanks!
29th Sep 2020, 3:27 PM
Yahel
Yahel - avatar
0
but my program still has a problem and its not working well. why is that?
29th Sep 2020, 3:31 PM
Yahel
Yahel - avatar
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.
29th Sep 2020, 8:20 PM
Yahel
Yahel - avatar
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..
30th Sep 2020, 2:20 PM
Jayakrishna 🇮🇳
0
https://code.sololearn.com/c146a4M3tGde so whats the problem now?
30th Sep 2020, 2:42 PM
Yahel
Yahel - avatar
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..
30th Sep 2020, 3:09 PM
Jayakrishna 🇮🇳
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
30th Sep 2020, 4:32 PM
Yahel
Yahel - avatar
0
oh, my bad... thank you! the whole code is good now!
30th Sep 2020, 4:40 PM
Yahel
Yahel - avatar