Exception in thread "main" java.lang.NullPointerException at gui.CataloguePanel.(CataloguePanel.java)
I'm trying to initialize a BookQuery
object in CataloguePanel
and call getBookList()
CataloguePanel.java
package gui;
import java.util.ArrayList;
import backend.Book;
import backend.BookQuery;
// Catalog panel. Shows the library titles' information and allows users to place their orders.
public class CataloguePanel extends JPanel implements GBPanel {
BookQuery bQuery;
ArrayList<Book> bookList = bQuery.getBookList(); // Here's where the error occurred
}
EDIT: http://www.reactionface.info/sites/default/files/imagecache/Node_Page/images/1314029819767.png
BookQuery bQuery;
ArrayList<Book> bookList = bQuery.getBookList();
bQuery
is not initialized, so it is similer like null.getBookList()
which must produce NullPointerException
. Either you initialize bQuery
. like -
BookQuery bQuery= new BookQuery();
Or make the getBookList()
method static
and call the method like -
ArrayList<Book> bookList = BookQuery.getBookList();