0

I've been coding in python for a while, but I just started learning java. I am building hangman currently and am getting a strange error. After running this code:

  System.out.println("Guess a letter: ");
  String userInput = input.nextLine();
  char letterGuessed = userInput.charAt(0);

it throws String index out of range. What's strange is that it doesn't even let me type anything in, and it just skips to the letterGuessed line. Does anyone know why this is happening?

Been-H
  • 33
  • 5
  • This is a guess, since the code is out of context, but the symptom fits, so I'm closing this as a duplicate of [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo). – Andreas Feb 14 '21 at 03:21

0 Answers0