Java NoSuchElementException问题
staticvoidsingle_start()throwsIOException,ContinueException,NoSuchElementException{St...
static void single_start() throws IOException, ContinueException, NoSuchElementException
{
String id;
System.out.println("Enter Player ID:");
int i=1;
while (i==1)
{
Scanner scan=new Scanner(System.in);
id=scan.nextLine();
scan.close();
Player player=new Player(id);
game(player);
System.out.println("Your total score is : "+player.getTotalscore());
set_recent_records(player.get_id(),player.getTotalscore());
set_top_records(player.get_id(),player.getTotalscore());
System.out.println("Another game?");
System.out.println("1.Try again");
System.out.println("2.Back to main menu");
i=scan.nextInt();
if (i==1){continue;}
if (i==2)
{
ContinueException e=new ContinueException();
throw e;
}
else
{
NoSuchElementException e=new NoSuchElementException();
throw e;
}
}
}
这段代码总是在 id=scan.nextLine();的时候报错,说Exception in thread "main" java.util.NoSuchElementException: No line found。这是为什么,谢谢 展开
{
String id;
System.out.println("Enter Player ID:");
int i=1;
while (i==1)
{
Scanner scan=new Scanner(System.in);
id=scan.nextLine();
scan.close();
Player player=new Player(id);
game(player);
System.out.println("Your total score is : "+player.getTotalscore());
set_recent_records(player.get_id(),player.getTotalscore());
set_top_records(player.get_id(),player.getTotalscore());
System.out.println("Another game?");
System.out.println("1.Try again");
System.out.println("2.Back to main menu");
i=scan.nextInt();
if (i==1){continue;}
if (i==2)
{
ContinueException e=new ContinueException();
throw e;
}
else
{
NoSuchElementException e=new NoSuchElementException();
throw e;
}
}
}
这段代码总是在 id=scan.nextLine();的时候报错,说Exception in thread "main" java.util.NoSuchElementException: No line found。这是为什么,谢谢 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询