First applet program compiles OK but gets runtime error

Hi Folks,

I just started programming in Java 2 weeks ago. The first few simple programs I wrote worked fine but today I wrote my first program which uses an applet to display a simple text string.

It compiles with no errors (using JDK1.2.2) but when I run it I get the following error "Exception in thread "main" java.lang.NoSuchMethodError: main"

Here is the code. Real simple, I am really stumped. Any ideas out there would be very much appreciated.

import javax.swing.JApplet;

import java.awt.Graphics;

public class WelcomeApplet extends JApplet {

public void paint ( Graphics g )

{

g.drawString ( "Welcome to", 25, 25 );

g.drawString ( "Java Programming!", 25, 40 );

}

}

Thanks Dennis

[789 byte] By [dduncan4615] at [2007-9-26 2:35:25]
# 1
If you want to run an applet from the DOS command line, you need to use the "appletviewer" command. Are you using the "java" command to run that applet?
rpk5928 at 2007-6-29 10:01:40 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2

As the other post said, you need to use appletviewer. You could do this two ways:

1. Add the applet tag to your java file as a comment before any import statements

/*

<applet code="WelcomeApplet" width="100" height="100">

</applet>

*/

then, at the command prompt:

appletviewer WelcomeApplet.java

OR

2. You could put the applet tag in an html file.

BUT for an applet that uses Java 2 classes, there are two requirements:

(i) The computer on which you are viewing the applet should have the JRE 1.3 plugin

(ii) You need to run your html file through the HTMLConverter (available at the sun site). This changes the applet tag to instruct the browser to use the plugin. If the plugin is not installed, it prompts the user to download and install the plugin.

HTH,

Dewang

dewangs at 2007-6-29 10:01:40 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3
Thanks guys. You hit the nail on the head. The tutorial I'm reading explained that but it tends to be a little verbose and and didn't get into that part until 4 or 5 pages after they presented the code.Patience being the operative word here...
dduncan4615 at 2007-6-29 10:01:40 > top of Java-index,Archived Forums,New To Java Technology Archive...