NoClassDefFoundError Applet Demo

时间:2015-07-31 20:09:24

标签: java applet noclassdeffounderror

I'm trying out a simple Applet demo from Java Tutorials - Getting Started With Applets but I am having problem the browser always says NoClassDefFoundError.

I have HelloWorld.java as

import

javax.swing.*;
import.java.lang.reflect.InvocationTargetException;

public class HelloWorld extends JApplet{
    public void init(){
        try {
            SwingUtilities.invokeAndWait(new Runnable(){
                public void run(){
                    JLabel label = new JLabel("Hello World!");
                    add(label);
                }
            });
        } catch (InterruptedException e) {
            System.err.println("createGUI didn't complete successfully");
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            System.err.println("createGUI didn't complete successfully");
            e.printStackTrace();
        }
    }
}

and my HelloWorld.html as

<html>
<head>
    <title></title>
</head>
<body>
<p> This file launches the 'A' applet: A.class! </p>
<applet code="HelloWorld.class" height=200 width=320>
    No Java?!
</applet>
</body>
</html>

I threw them under the /var/www/html/ folder on my debian machine running apache, added this server to security exceptions in Java control panel and tried to open http://ip_add_address_of_apache_server/HelloWorld.html I'm encountered with the error

NoClassDefFoundError 

HelloWorld$1

HelloWorld.java was under the root source folder of my IDEA module, it's not within a package.

1 个答案:

答案 0 :(得分:0)

All of the .class files for your code need to be on the classpath. I would highly recommend packaging your code into a JAR file and placing that JAR on the classpath in your HTML wrapper.