aspose file tools*
The moose likes Beginning Java and the fly likes Swing File Error: error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Swing File Error: error "NoSuchMethordError"." Watch "Swing File Error: error "NoSuchMethordError"." New topic
Author

Swing File Error: error "NoSuchMethordError".

divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
Hello,

I am runing Swing program first time . While running it show me error "NoSuchMethordError".
Source Code is:

import java.awt.*;
import javax.swing.*;

class MyDrawPanel extends JPanel
{
public void paint (Graphics g)
{
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MyDrawPanel());
frame.setSize(150, 150);
frame.setVisible(true);
}
}
Please tell me where I went wrong.
Thanks
Divya
[ April 25, 2007: Message edited by: divya sharma ]

Divya
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39879
    
  28
Please provide more details about the error.
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
Error is appeared as:

Exception in thread "main" java.lang.NoSuchMethodError:main
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
What command line did you use to run it?
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Do you have a MyDrawPanel.class file which is older than MyDrawPanel.java? You could be trying to run an old version of the class. You may want to delete all .class files and recompile.


"I'm not back." - Bill Harding, Twister
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
I have made some change in my code i.e.

import java.awt.*;
import javax.swing.*;

public class MyDrawPanel
{


public static void main(String[] args)
{
MyDrawPanel p1= new MyDrawPanel();
p1.go();
}

public void go()
{
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Hello h1 = new Hello();

frame.getContentPane().add(h1);
frame.setSize(300,300);
frame.setVisible(true);


}
class Hello extends JPanel
{
public void paint (Graphics g)
{
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
}
}




Now, it's working. So for swing you have Frame & Panel; is that so?

Thanks
Divya
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Swing File Error: error "NoSuchMethordError".