Hey guys. Need your help again.
I have to make a Library that contains books.
In the Library class, a method called mostPagesBook, returns the book with most pages. It compiles, but errors when run:
Exception in thread "main" java.lang.NullPointerException
at Library.mostPagesBook(Library.java:32)
at TEMP.main(TEMP.java:29)
(POINTING AT THE pages = checkBook.getNumPages(); Line)
In Library:
in Book :
Help is most appreciated.
I have to make a Library that contains books.
In the Library class, a method called mostPagesBook, returns the book with most pages. It compiles, but errors when run:
Exception in thread "main" java.lang.NullPointerException
at Library.mostPagesBook(Library.java:32)
at TEMP.main(TEMP.java:29)
(POINTING AT THE pages = checkBook.getNumPages(); Line)
In Library:
Code:
public Book mostPagesBook ()
{
int bookNumber = 0, pages, mostPages = 0, largestBook = 0;
for (Book checkBook : bookList)
{
pages = checkBook.getNumPages();
if (pages > mostPages)
largestBook = bookNumber;
bookNumber++;
}
return bookList[largestBook];
}
in Book :
Code:
public int getNumPages ()
{
return numPages;
}
Help is most appreciated.