我正在为一个静态方法做扫描仪,并发生这个异常:
Exception in thread "main" java.util.NoSuchElementException: No line found
Run Code Online (Sandbox Code Playgroud)
我的修改方法倾向于从控制台获取 2 个字符串作为输入,但它不起作用。
注意:我没有使用scanner.close();
static ArrayList<Book> modBook(){
Book tempbook = Book.searchTitle();
if(tempbook !=null){
Scanner sc = new Scanner(System.in);
int i = BookList.indexOf(tempbook);
System.out.println("Please enter title:");
String booktitle = sc.nextLine();
System.out.println("Please enter author:");
String bookauthor = sc.nextLine();
tempbook.setTitle(booktitle);
tempbook.setAuthor(bookauthor);
BookList.set(i, tempbook);
}
return BookList;
}
Run Code Online (Sandbox Code Playgroud)
我的搜索方法:
static Book searchTitle(){
try (Scanner input = new Scanner(System.in)) {
String booktitle;
System.out.println("Please enter title:");
booktitle = input.nextLine();
for(Book b : BookList){
if(b.getTitle() != …Run Code Online (Sandbox Code Playgroud)