File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes java.lang.NoSuchMethodError ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "java.lang.NoSuchMethodError ??" Watch "java.lang.NoSuchMethodError ??" New topic
Author

java.lang.NoSuchMethodError ??

Brian Wieb
Greenhorn

Joined: Apr 14, 2005
Posts: 4
Hello,
I'm using the Head First Java book, chap. 12, page 364.
The example program given creates the following error trying to run it.
"Exception in thread "main" java.lang.NoSuchMethodError: Main"

Does anyone know why I am getting this error? Also any suggestions on where
to look for explanations of these types of errors?

This is the example program from the book...

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);
}
}

Thanks !
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
This isn't the whole code is it? You are missing your main method.
Brian Wieb
Greenhorn

Joined: Apr 14, 2005
Posts: 4
OK, I'm new at this...Very new! The book only has the code I listed above. Maybe it's assumed I know what I'm doing? I added a main method listed below, now it runs but produces nothing.
I must still be missing something but I don't have a clue what it would be.
Any ideas???

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

class MyDrawPanel extends JPanel {
public static void main (String[] args) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.getContentPane();

}

public void paintComponent(Graphics g) {

g.setColor(Color.orange);

g.fillRect(20,50,100,100);
}

}
Timmy Marks
Ranch Hand

Joined: Dec 01, 2003
Posts: 226
If you are that new to this, I would say what you are missing is chapters 1 through 12

Seriously though, it will be of great benefit to you to understand what is going on before you try this application. You need to know a lot of things before the code you have posted here will work.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: java.lang.NoSuchMethodError ??
 
Similar Threads
Help with graphics
Help - Exception
This program is throwing back error
Not sure if this the place??
compiler error in the Party.java on page 3