This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting a NullPointerException but really don't know why

 
Ronald Castillo
Ranch Hand
Posts: 47
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, I got a little problem

This is the code I'm using:

I trimmed the non-relevant stuff, including the validation code




The error:
java.lang.NullPointerException
blackbelt.domain.ShoppingCart.add(ShoppingCart.java:12)
be.loop.servlets.AddToCartServlet.doGet(AddToCartServlet.java:39)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)


However, I've made sure that the variable "libro" actually contains a book and not a null reference object.

I can't see where's the problem at ... If you do, what am I doing wrong?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're not even looking in the right file. The NPE is happening in ShoppingCart, not the servlet.

Hint: look closely at ShoppingCart. The problem should be almost immediately obvious.
 
Ronald Castillo
Ranch Hand
Posts: 47
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:You're not even looking in the right file. The NPE is happening in ShoppingCart, not the servlet.

Hint: look closely at ShoppingCart. The problem should be almost immediately obvious.


Oh, sorry. I know it's happening on the ShoppingCart file. Added the other file just in case.
However, I'm not able to see what the problem is. O.o Maybe I'm a little too tired, but can't really see what the issue is.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where, in ShoppingCart, does the list instance get created?
 
Ronald Castillo
Ranch Hand
Posts: 47
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Where, in ShoppingCart, does the list instance get created?


I was just running another test and just noticed that. I'm really sorry about the stupid mistake -_-"
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to be sorry. But I'll bet it's a mistake you won't make again!
 
Ronald Castillo
Ranch Hand
Posts: 47
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hopely not, thanks Bear!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic