• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 642
  • Last Modified:

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.
0
Lost_User
Asked:
Lost_User
  • 3
1 Solution
 
Lost_UserAuthor Commented:
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

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

http://docs.oracle.com/javase/tutorial/deployment/applet/getStarted.html
0
 
Lost_UserAuthor Commented:
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"
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
Failed to run due to "Exception in thread "main" java.lang.NoSuchMethodError: main"

Was the above error whilst trying to run it in a console?

Again, as stated above, java programs and applets are two different things. You run java programs (those that have "main" functions) in the console, etc and you run applets (those that extend from JApplet and such) from the html in web pages. The other way around will not work!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now