更新时间:2023-11-18 17:04:34
不要关闭setConnection()
中的扫描仪teclado
.关闭扫描程序也会关闭其关联的流.然后在askToDo
中,当您创建另一个扫描仪时,System.in已经关闭.
Don't close the Scanner teclado
in setConnection()
. Closing a Scanner also closes its associated stream. Then in askToDo
, when you create another Scanner, System.in is already closed.
您应该有一个用System.in初始化的***静态Scanner对象,并在类中的任何地方使用该对象,而不是在每个方法中创建一个新的Scanner.
You should have a single top-level static Scanner object, initialized with System.in, and use that everywhere in your class instead of creating a new Scanner in each method.