Link to home
Start Free TrialLog in
Avatar of Lost_User
Lost_User

asked on

Java Applet wont load on HTML file

Hi,

I am trying to upload my java that i have worked on and it is throwing an excepection.

Jave: Helloworld.java
 
class Helloworld {
	 public static void main(String args[]){
	     System.out.println("Hello World");
	  }
 }  

Open in new window


HTML:
<html>

<body>
<h2>My first Java program</h2>
	<applet code="Helloworld.class" height="200" width="250">
	</applet>
</body>
</html>

Open in new window


Error:
" Application Error
 RuntimeException
 java.lang.reflect.InvocationTargetException"

Open in new window


I am able to compile the java view it in console but when I load the html file it throws the above error.
Avatar of Lost_User
Lost_User

ASKER

I have also used this java with no result.

 import java.applet.Applet;
 import java.awt.*;
 
 class Helloworld extends Applet{
	 public static void main(String args[]){
	     System.out.println("Hello World");
	  }
 }  

Open in new window

Applets are not simple java programs. There is a tutorial you should read
I have used that also and it throws the same error...

http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;

public class Helloworld extends JApplet {
    //Called when this applet is loaded into the browser.
    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    JLabel lbl = new JLabel("Hello World");
                    add(lbl);
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }
}

Open in new window


Failed to run due to "Exception in thread "main" java.lang.NoSuchMethodError: main"
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial