Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Geoff Jefferson
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20552
57
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic