my dog learned polymorphism*
The moose likes Beginning Java and the fly likes compilation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "compilation error" Watch "compilation error" New topic
Author

compilation error

Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear friends,
please help me.
I have to close B_Frame (Child frame) from A_Frame (Parent) with a button click.
In A_Frame.java (Parent Frame) I used like this :
public void closeChildFrame()
{
System.out.println("close()");
B_Frame.hide();
B_Frame.dispose();
}
Compilation error :
non-static method hide() cannot be referenced from a static context B_Frame.hide();
^
non-static method dispose() cannot be referenced from a static context
B_Frame.dispose();

please help me.
your kind cooperation would be greatly appreciated.
Thanks in advance.
John Utting
Greenhorn

Joined: Mar 05, 2002
Posts: 16
Rajesh,
You are trying to invoke the instance methods
hide() and dispose() using the class reference (B_Frame) rather than using an object of the class.
Try the following:
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
When youi call the closeChildFrame() method pass a reference to an object of type B_Frame.
Hope this helps.


SCJP 1.4 SCWCD...
Rajesh Kumar
Greenhorn

Joined: Nov 16, 2001
Posts: 28
Dear John,
I am deeply grateful to you for your kind cooperation.
I made changes in closeChildFrame method. It is ok. but it is giving problem when i call that method.
please see this one.
Thank you very much.
Yours
Rajesh
jMenuItem_close.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
closeChildFrame();
}
});
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
error : cannot be applied to closeChildFrame();
please help me, what changes shall i do to avoid this error.
I am new to java.
Thanks once again.
Originally posted by John Utting:
Rajesh,
You are trying to invoke the instance methods
hide() and dispose() using the class reference (B_Frame) rather than using an object of the class.
Try the following:
public void closeChildFrame(B_Frame child)
{
System.out.println("close()");
child.hide();
child.dispose();
}
When youi call the closeChildFrame() method pass a reference to an object of type B_Frame.
Hope this helps.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: compilation error
 
Similar Threads
Polymorphic Method Call
Struggling With Passing Data Between Data Access Class, Business Bean, and Controller
how can we import a package ?
compile time errors
True or False