Forum Stats

  • 3,854,655 Users
  • 2,264,394 Discussions
  • 7,905,747 Comments

Discussions

Exception in thread "main" java.lang.NoSuchMethodError : main

817165
817165 Member Posts: 2
edited Nov 22, 2010 8:06PM in Java Desktop Applications
Hi everyone I am beginner with Java and probably not first who encountered problems with compiled source code. I give an example of my code it comes from a book "Head First Java" page 28 this code looks like this :

import java.awt.*;
import java.awt.event.*;
class Party {
public void makeInvitation(){
Frame f = new Frame();
Label l = new Label("Party at Toms");
Button b = new Button("Sure!");
Button c = new Button("Eee...");
Panel p = new Panel();
p.add(l);
}
}

after I compiled it as Type of file : CLASS file


In Command Prompt I write : java Party and this error like : Exception in thread "main" java.lang.NoSuchMethodError :main

I struggle with this for 3weeks :( Can anyone can help....

Thank you in advance Artur
Tagged:

Answers

  • 817194
    817194 Member Posts: 10
    edited Nov 22, 2010 8:06PM
    you don't have a main routine
    to call this method you should declare a main routine with :
    public static void main(String[] str)
    {
    ..
    .....
    call to your method ....
    }
    nested in you class off course

    Edited by: 814191 on Nov 22, 2010 5:05 PM
This discussion has been closed.