• Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.NoSuchMethodError ??  RSS feed

 
Brian Wieb
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't the whole code is it? You are missing your main method.
 
Brian Wieb
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 226
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!