• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Don't understand this error message from JUnit

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Recently, I chanced upon this Java Ecommerce code here at https://codereview.stackexchange.com/questions/224425/java-shopping-cart-design

However, when I tried to run the JUnit test, it gives error at this line :



Basically, Junit testing is quite alien to me and I need some help to understand about what the error message is trying to tell me.


It says Java.NullPointerException
at CartItem barCodedItem_1 = new CartItem(bean_can);



As this is a review from stackExchange, I thought the code would be running perfectly but it is not....

Hope someone can tell me if there is something wrong with the code at CartItem class.

Thanks.
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has nothing to do with JUnit. It's just plain Java telling you that something is null when it shouldn't be null.

Where have you declared bean_can and what value have you assigned to it?
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That can't be the full stacktrace, as that line would not (by itself) throw a null pointer.
 
Rancher
Posts: 261
12
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did not check the entire source code, but it seems that Product has a field Price but I did not immediately see its class declaration...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic