When searching for a book in a book store, say the object is a book, each book object would have a title, author, ISBN code etc.
Say I enter an ISBN as a String using `scan.next()'
I take this input and use it to find the object in the arraylist as follows:
public Book searchISBN (String givenISBN){
Book foundBook = null;
for(Book findISBN : bookStore){
if(findISBN.getISBN().equals(givenISBN)){
foundBook = findISBN;}
}
retu foundBook;
I'm currently having problems with null pointer exception in the line which has the if statement.
I do not understand why this is. When I include the following piece of code, which has the aim of setting any book that has a null classification equal to a specified classification:
if(selectedBook.getISBN().equals(null)){...
I get a null pointer exception if I run with the above line of code in. There is a waing at this line stating 'object equals null is never true', in the class that creates the book object String ISBN = null, as the intention is to set a value for this in a different class which creates objects for the book store where half the books in my collection are set an ISBN. The other half are meant to be set ISBNs if they equal null (in the main method
No idea what to do with this.
