This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Cannot make a static reference to the non-static method add() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Cannot make a static reference to the non-static method add()" Watch "Cannot make a static reference to the non-static method add()" New topic
Author

Cannot make a static reference to the non-static method add()

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi

I have made a simple class as shown below





When i tried this , i am getting this compile time error :

Cannot make a static reference to the non-static method add()

Please tell me whats the mistake i am making here .


Save India From Corruption - Anna Hazare.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Just what it says. The add method is not static and you are calling it as if it were.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234



Thanks .
forgot to create the Object for that interface .
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

First you need to create an implementation and then create an instance of it


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Thanks , i already created that , but did not post as the question might look too lengthy.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Cannot make a static reference to the non-static method add()