File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes static class wondering Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static class wondering" Watch "static class wondering" New topic

static class wondering

Shay Gaghe
Ranch Hand

Joined: Sep 03, 2001
Posts: 102
I used a static method that I made to invoked a non-static method that the java team made. In the compiling time I receive a compiler error:
"": Error #: 308 : non-static method remove(java.awt.Component) cannot be referenced from a static context at line 76, column 5
I understand that the invoked �remove() has to be static or move the static declartion from the invoker method.
In my case I must the invoker method to be static , since I don�t have control on remove()
What should I do??
And second , I declare my class static. Im not sure that im understand the use of static in a class declaration , but though I put static modifier in the class declartion and I receive this error :
"": Error #: 217 : modifier static not allowed here at line 8, column 15
can you explain a bit about the static vs class relationship? What the rules about the variables that inside a static class??
Thanks in advance
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
You cant have a static class, unless its an inner class but judging by your error message it isn't.
You also can't call a non-static method from a static method, unless you create an instance of the class. This is because the static method is not associated with an instance of the class, while the non-static method is.
Try constructing an instance of the class from inside the static method before you call the non-static method. Im not usre if this will suit your needs because I dont know what your cde looks like. Maybe you could post some of the code here.

[This message has been edited by BJ Grau (edited September 15, 2001).]
I agree. Here's the link:
subject: static class wondering
It's not a secret anymore!