I have a bean class, which accesses a data access object interface and the concrete class that implements that interface; therefore, I have a statement like:
There is a static method in this bean class. I got a compilation saying that the instance with the type of the data access object interface cannot be referenced from a static context:
EditorBean.java:42: non-static variable ed cannot be referenced from a static context return ed.findEditor( username );
Your 2 choices are to 1. Make the method non-static ( instance ) 2. Make the EditorDAO attribute static depends on which one makes sense. Otherwise, say you have
now which ed object is the findEditor( username ); going to be called from? the one from b1 or the one from b2? that's why the java compiler is complaining. Jamie
but on further inspection, I wondered why you passed an EditorBean into the findEditorData() method when you don't ever use it. So I think that you may want to reference the parameter EditorBean's ed object. You just have to change your code to say that you want to use the ed object from the EditorBean parameter:
Now the compiler knows which ed object you want to call the findEditor method on. Jamie [ November 28, 2003: Message edited by: Jamie Robertson ]
JiaPei Jen
Ranch Hand
Joined: Nov 19, 2000
Posts: 1309
posted
0
Thanks for your reply. I deleted the second parameter in the findEditorData(); But, I am still not out of the woods. Now, please help me with my conceptual problem: 1. I got "non-static variable ed cannot be referenced from a static context"
when my code is
The error message was the same after I changed to
2. I then made findEditorData( String username ) non-static
I got this compilation error:
[ November 28, 2003: Message edited by: JiaPei Jen ]