• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Don't understand this error message from JUnit

 
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • 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: 12253
259
  • Mark post as helpful
  • send pies
  • 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?
 
Master Rancher
Posts: 4663
49
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic