Win a copy of liveProject: Build an ML Recommender System this week in the Artificial Intelligence and Machine Learning forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • paul wheaton
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • Mikalai Zaikin
  • Himai Minh

Don't understand this error message from JUnit

 
Ranch Hand
Posts: 748
  • 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: 12916
281
  • 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...
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic