Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

what's missing ?? >>java.lang.NoSuchMethodError: main 1

Status
Not open for further replies.

DBugger

Programmer
Nov 3, 2002
4
AE
Hi

Hope there's room for some beginners,I'm gettin this error "java.lang.NoSuchMethodError: main

Exception in thread "main" " for the following code,
"import java.applet.Applet;
import java.awt.Graphics;

public class HelloWorld extends Applet {
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}"

I think some binary files are missin, but where do I get them from??
 
If you want to run a java Class, it MUST contains a "main" method. This method will be the entry point of your program. Water is not bad as long as it stays out human body ;-)
 
The 'main' method can be thought of the point of entry to a programme is the programme is to be run standalone (rather than instantiated by another class, but thats another story).

You must have a main method if you are going to run 'standalone' - ie on command line -
Code:
java MyClass
if you see what I mean ...

Code:
public class HelloWorld {

    public void sayHello() {
        System.out.println("Hello world!");
    }
 
    public static void main(String args[]) {
       HelloWorld hw = new HelloWorld();
       hw.sayHello();
}

Applets are a different story, as often an [code]init()
method is used as well as other methods considered 'good form' when writing applets. However I wont go into Applets as I think they are crap, and have never used them !!! There are far better ways of performing generic 'applet' tasks remotely, using servlets, rmi, networking and so forth.

</another story>
 
should be another
Code:
 }
at the end of that example ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top