13 AnswersNew Answer
static String secretWord ; //assign something like this, => empty atleast => =""; otherwise this next one cause error... static char lettersOfSecretWord = secretWord.toCharArray();
Can you say what are trying with that code...?
Remove this from the function takeUserinput() and add it before function at class level after ArrayList declaration.. Scanner scan = new Scanner(System.in);
You have space initially to static String secretWord = " "; Make it to static String secretWord = "";
Yes. Good one.. Do add description next time to get quick response if you want...!! You're welcome....
but my program still has a problem and its not working well. why is that?
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.
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..
https://code.sololearn.com/c146a4M3tGde so whats the problem now?
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..
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
oh, my bad... thank you! the whole code is good now!