我有这个简单的代码:
public class Example {
public Example() {
Scanner scanner = new Scanner(System.in);
int row = scanner.nextInt(); // exception at this line
scanner.close();
}
public static void main(String[] args) {
Example ex1 = new Example(); // this line successfully operate
Example ex2 = new Example(); // exception : no such element exception at above line
}
}
我不知道为什么当代码运行到 ex2 时我总是收到此异常。