Re: "Exception in thread "main" java.lang.nosuchmethodError: main"



keith vescovo via JavaKB.com wrote:
I keep getting this message when trying to run a java program that
calculates the hypotenuse of a right triangle.  The program will compile,
but it won't run.  Could someone please help me with this?  Any help will
be greatly appreciated.  Here is the code for my program:


[subject="Exception in thread "main" java.lang.nosuchmethodError: main"]

That error means that the class doesn't have a static method with the signature "void main(String[])".

But I notice that your class is an Applet. Ah! Create the following html file and save it in the same directory as your class:

//--- Triangle.html (do not include this line)
<html>
	<head></head>
	<body>
	<applet code="Triangle.class" width="300" height="100"></applet>
	</body>
</html>
//--- (do not include this line)

And then, from the console, run: appletviewer Triangle.html
or load the html file in your web browser (make sure the .class file is in the same directory).



If you want to run the class with the java command, you must create a public static method called main:


//---
public static void main(String[] args) { ... }
//---


-- Peter MacMillan e-mail/msn: peter@xxxxxxxxxxxxx .



Relevant Pages

  • Its easy to do but why it doesnt works??
    ... HTML Test Page ... Now i have to import this applet into my jsf application. ... The strange fact is that when i run it from html file everythings go ...
    (comp.lang.java.programmer)
  • Re: launch applet with APPLET or PLUGIN
    ... >..I use an applet. ... > HTML file, ... > I launch it in a JSP file: ... Let me start with HTML (the inconsistencies between browser ...
    (comp.lang.java.programmer)
  • Re: Problems with web page
    ... > files, and html page, and when I run the html document, with ... > appletviewer, or Mozilla, or Explorer, the applet starts ... But when I move all the html file, ... > using the same imports, have worked fine on the web page. ...
    (comp.lang.java.programmer)
  • Re: Automating steps to copy URL from IE into Word
    ... Inside an html document, VBScript is contained between script tags. ... you can create an html file and convert it to an hta file ... > webpage document and it would run when the webpage was opened? ... However, if the document is open, it opens a second ...
    (microsoft.public.word.vba.general)
  • Re: problem: security using IDEs appletviewer
    ... APPLET tag. ... The HTML above loads both the test1.jar and test2.jar and runs the class ... You have the image in a in a jar that has the name ... appletviewer will load all .jar files listed there. ...
    (comp.lang.java.help)