• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Don't understand this error message from JUnit

 
Ranch Hand
Posts: 821
  • 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: 13256
292
  • 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...
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic