*
The moose likes Beginning Java and the fly likes Need Help with this err  non-static method getRowCount() cannot be referenced from a static context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need Help with this err  non-static method getRowCount() cannot be referenced from a static context " Watch "Need Help with this err  non-static method getRowCount() cannot be referenced from a static context " New topic
Author

Need Help with this err non-static method getRowCount() cannot be referenced from a static context

Geoff Jefferson
Ranch Hand

Joined: Apr 09, 2009
Posts: 102
Hello,

I created a GUI using the Netbeans framework. From that interface I have a JButton, and within the actionPerformed method of that button is the following code.
The main() method is in the same class.
I tried moving it ( main() )to another class, and calling setVisible() from there to fire up the interface, hoping to have some effect
on the 'static context'.

Obviously I don't fully understand what is going on here with the 'static context', and my question would be, in this case, what does it mean?
I know what a static member is, and what a static method does, at least fundamentally.
I have a general idea that main() is static because the run-time environment will be looking for it as specified by the Standard.

Hopefully my eyes have glazed over and I am missing something simple, and that another pair of eyes will quickly point out.
Otherwise, I'm need to brush up on whatever I don't know here.

I thought this to be a good minimalist starting point regarding the posting of code.

Thanks.

Rahul P Kumar
Ranch Hand

Joined: Sep 26, 2009
Posts: 188
getRowCount() is not static method means..it is not a class method, rather it is an instance method. Only class method can be invoked by Class.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

To call a non-static method you need an instance of the class. In your case, you need an instance of CarrierTableModel (you know, new CarrierTableModel(...)). Either that, or make the method static (if possible).

This is really a beginner's question, so moving to Beginning Java.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
wood burning stoves
 
subject: Need Help with this err non-static method getRowCount() cannot be referenced from a static context