So I'm working on this energy tree project for my computer programming class, I was trying to make a do-while loop that asked the user if they were a producer or consumer and if any other input was entered loop would start over. My code keeps getting the error
"java.util.NoSuchElementException" on line 45
where it says
char Type = ProducerOrConsumer.nextLine().toUpperCase().charAt(0);
boolean isChoiceValid = false;
do
{
PETCScanner.close();
Scanner ProducerOrConsumer = new Scanner(System.in);
System.out.println("Are you a Producer or a Consumer?\\\\n (P = Producer, C = Consumer");
char Type = ProducerOrConsumer.nextLine().toUpperCase().charAt(0);
if (Type == 'P' || Type =='C')
{
}
else
System.out.println("Sorry try Again");
{
}
String Name = ProducerOrConsumer.nextLine().toUpperCase();
System.out.println(Name);
}while(isChoiceValid == (true));
System.out.println("You're Done!");
}
{}outside the else?