ERROR [STDERR] java.lang.NullPointerException - can't solve
bertoz84 Apr 18, 2011 1:11 PMHi all, i really need help to overcome this error.
I'm going to paste the interesting parts of my code:
TEST BEAN ( we are inside a method called by the java test client ):
.
.
.
try {
System.out.println("lowering the amount of the selected book");
Book abook = (Book) bookop.findByISBN(80002).get(0); // Book is an entity bean --- bookop is the istance of a session bean that performs // operations on Book
bookop.updateMin(abook.getISBN(), 2); // tot - 2
// OPERATION updateMin DONE SUCCESSFULLY
} catch (Exception e) {
e.printStackTrace();
}
Users an_user = (Users) user.findByUser("mouse").get(0); // Users is an entity bean --- user is the istance of a session bean that performs // operations on Users
cart.checkoutCart(an_user); // cart is the istance of a session statefull bean that performs classic operations like in a web site ( bookshop )
// to see what this method go down
-end
CART BEAN ( the called method ):
public void checkoutCart(Users customer) {
for (int i = 0; i < books.size(); i++) // where books is: private List<CartBook> books , a simple class made up of a Book and the quantity // to purchase of that book
{
Book abook = books.get(i).getBook();
Integer quantity = books.get(i).getQuantity();
try {
System.out.println("lowering the amount of the selected book");
DBOperation.updateMin(abook.getISBN(), quantity); // DBOperation is the same as bookop seen before
// ERROR [STDERR] java.lang.NullPointerException
} catch (Exception e) {
e.printStackTrace();
}
}
}
-end
so basically the code is the same; the difference is that going through the cart bean i can lower the quantity of a list of books ( that are the books that a customer puts in his cart: when he performs a checkout operation the method updateMin lowers the amount of every books purchased in the store ) instead of only one.
the problem is that through the cart i get always the ERROR [STDERR] java.lang.NullPointerException in the DBOperation.updateMin methods that is exactly the same of bookop.updateMin.
Every cicle of the for( ) command i get this error.
I can assure that my list is not empty and abook & quantity are not null.
I really don't get the problem!
Thank you in advance!!