my dog learned polymorphism*
The moose likes Beginning Java and the fly likes NoSuchMethodError!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoSuchMethodError!!!" Watch "NoSuchMethodError!!!" New topic
Author

NoSuchMethodError!!!

divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
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);
}
}


Divya
satishkumar janakiraman
Ranch Hand

Joined: May 03, 2004
Posts: 334
Hi,

Its because the main method is missing

bye for now
sat
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
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.


Rahul Bhattacharjee
LinkedIn - Blog
divya sharma
Ranch Hand

Joined: Jan 25, 2007
Posts: 87
So what's a solution for this ??
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

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



[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoSuchMethodError!!!