I'm trying to build a library type-program in java, but I'm having some trouble with storing user input in my ArrayList. I have an ArrayList called 'list
' that stores the title
, author
, publisher
, genre
, year
and pages
of the book and I need to allow users to input books to the ArrayList to later be able to view all the books stored in the ArrayList.
When I run the program it's throwing this error:
Exception in thread "main" java.lang.NullPointerException
at thelibrary.addBooks(Book.java:73)
at Menu.bookmenu(Menu.java:68)
at Menu.main(Menu.java:27)
Where am I going wrong?
public static void addBooks() {
Scanner newBooks = new Scanner(System.in);
ArrayList<Book> list = null;
for (int i = 0; i < 1; i++) {
System.out.println("\n\nAdd a new book to the library:");
list.add(new Book(title, author, publisher, genre, year, pages));
}
System.out.println("You have successfully added a new book to the library!");
}