• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.NoSuchMethodError ??

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 !
 
Ranch Hand
Posts: 226
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic