Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoSuchMethodError!!!

 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello once again,

I am running this code while compilling no error displayed but while running it .. message displayed "error thread NoSuchMethodError"

Code is:

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

class MyDrawPanel extends JPanel
{
public void paintComponent(Graphics g)
{
g.setColor(Color.orange);
g.fillRect(20,50,100,100);
}
}
 
satishkumar janakiraman
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Its because the main method is missing

bye for now
sat
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by divya sharma:
Hello once again,

I am running this code while compilling no error displayed but while running it .. message displayed "error thread NoSuchMethodError"

Code is:

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

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


classes used during compilation might be different from that used in runtime .So method might not be there.
 
divya sharma
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's a solution for this ??
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by divya sharma:
So what's a solution for this ??


If your application consists of just this one class, then the problem is, as the first response states, that you don't have a "public static void main(String[] args)" method. Without one, you don't have an application, merely a class.

To use this one class, you need a minimal main() method. It would have to create a JFrame, put your JPanel into it, set the size of the JFrame and call setVisible(true) on the JFrame to make it appear on the screen. Something like

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic