Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing File Error: error "NoSuchMethordError".

 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please provide more details about the error.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Error is appeared as:

Exception in thread "main" java.lang.NoSuchMethodError:main
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What command line did you use to run it?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic