使用" scanner.hasNextLine()"在线程内部,它会导致我的main方法无限重复。
以下是代码:
for (var i in imageCheer) {..}
我还要注意,当我使用" while(true)"我没有遇到这个问题。非常感谢任何帮助!
答案 0 :(得分:1)
像这样修改你的线程:
@Override
public void run(){
while(scanner.hasNextLine()){
System.out.println("Has Next");
scanner.nextLine();//move to next
}
}