Adding elements to a Jlist

I['m trying too add elements from a text file to a Jlist, so I've set up the list with a defaultListModel, and read the objects from the text file into an object array.

Now all I want is one of the variables of the object (title to be precise) to be added to the listmodel, so I use:

for(i=0; i < BookList.length; i++){

bookModel.addElement(BookList.getTitle());

}

where getTitle returns a string value with the title in it. But the addElement command asks for an object parameter, so it compiles ok but when I run I get a nullPointerException.

Is there any way I can do this?

Stu

[649 byte] By [jedi Stu] at [2007-9-26 7:45:50]
# 1
bookModel.addElement(BookList.getTitle());Either bookModel is null or the getTitle() method is returning a null. If it is the getTitle() method, you could change the method to return an empty string if the title is null.
pasteven at 2007-7-1 17:54:08 > top of Java-index,Archived Forums,Swing...