• Post Reply Bookmark Topic Watch Topic
  • New Topic

non-static method error  RSS feed

 
Raven Ramirez
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error: Non-static method calcCost() cannot be referenced from a static conext

Have no idea how to make this method work on the main class. That error is just Japanese to me since I tried changing alot of things to static, which made it worse =p here the three classes i have and the error happens in the main class





 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
look at these two lines:


You create a PizzaOrder object, and name it pizzaOrder. Then you call the calcCost using the CLASS name, not the reference variable name...

try doing
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your case on this line:

The compiler thinks you are trying to access the calcCost method statically i.e. using the class name PizzaOrder. But the instance of this class you have created on the previous line is named pizzaOrder. Can you see your mistake now?

[Edit] Scrap that, just read what Fred has written above!
 
George Avilez
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oh man that's emberassing haha thank you guys
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!