我的学业有问题,希望我能在这里得到一些帮助!显然在第 17 行有一个 nullpointerexception 错误。
import java.util.*;
import java.text.*;
public class Librarian {
private ArrayList<Book> bookList = new ArrayList<Book>();
public Librarian() {
bookList = new ArrayList<Book>();
}
public ArrayList<Book> findBooksWrittenBy(ArrayList<Book> bookList, String author) {
ArrayList<Book> booksByAuthor = new ArrayList<Book>();
for(int i = 0; i < bookList.size(); i++) {
Book book = bookList.get(i);
String author1 = book.getAuthor();
if(author1.equalsIgnoreCase(author)) {
booksByAuthor.add(book);
}
if(booksByAuthor.size() != 0) {
booksByAuthor = booksByAuthor;
}else {
booksByAuthor = null;
}
}
return booksByAuthor;
}