Applet Error - NoClassDefFoundError

I understand that there are a million of these messages, but none of them helped me, and so: I am trying to deploy a very simple applet that will not load properly. My HTML:

<html>
<head>
    <meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
   <applet code = "SimpleApplet.class"
   width = "320" height = "100"></applet>
</body>
</html>

My Java:

package test;

import javax.swing.*;   

public class SimpleApplet extends JApplet{
   public void init(){
      try{
        SwingUtilities.invokeAndWait(new Runnable(){
          public void run(){
            JLabel lbl = new JLabel("Hello World");
            add(lbl);
          }
        });             
      }
      catch(Exception e){
        System.out.println(e);
      }
   }
}

Both files are in the same directory.

/home/me/workspace/myProject/bin/test

If I run the applet myself through Eclipse, it works fine. When I open the page, I get an error

java.lang.NoClassDefFoundError: SimpleApplet (wrong name: test/SimpleApplet)

The error suggests that I misplaced or named something. However, having tried

<applet code = "test/SimpleApplet.class"
width = "320" height = "100"></applet>

<applet code = "SimpleApplet.class"
codebase = "/test"
width = "320" height = "100"></applet>

, ", .java, , ClassNotFoundException. , classpath codebase ( ) . jar . - , ?

+5
3
  • /// /MyProject/
    • applet.html
    • /// /MyProject//
      • SimpleApplet.class

SimpleApplet test, HTML ( ) HTML-.

<html>
<head>
    <meta http-equiv="Content-Type" content"text/html; charset=utf-8">
</head>
<body>
   <applet code = "test.SimpleApplet"
   width = "320" height = "100"></applet>
</body>
</html>

:

  • , , , . ; , .
  • . , , .
+7

, ", .java

test/SimpleApplet.java, test/SimpleApplet.class. SimpleApplet.java SimpleApplet.class

, , ,

<applet code = "SimpleApplet.class"
codebase = "/test"
width = "320" height = "100"></applet>

As/test - , .

0

NoClassDefFoundError: Ahmed (wrong name: intoapplet/Ahmed )

3 .

:

'Coding', , 'Test'.

, Java. . ( eclipse).

---------------------------------- Java-: ---------- ----------------------

    import java.awt.*;
    import javax.swing.*;

    public  class  Ahmed extends JApplet {

    private static final long serialVersionUID = 1L;

    public void paint(Graphics g){
    super.paint(g);
    g.drawString("my name is Ahmed Zaki wow this actually
    works",300,300);                     
    }
    }

---------------------------------- HTML ----------- -----------------------

    <html>
    <head>
    <title>Tutorial applet</title>
    </head>
    <body>

    <Applet code="Ahmed.class"   width="400"; height="300";> 

    </Applet>
    </body>
    </html>

------- SFTP, FTP, WebDAV SCP- -------

Both class and html files in the / public_html / folder using "WinSCP", which is free and open source SFTP, FTP, WebDAV and SCP client for Microsoft Windows. Its main function is to securely transfer files between local and remote computers.

    example:

    directory for html file = /public_html/index.html
    directory for class file = /public_html/Ahmed.class

    example no2:

    +-- public_html
    |   +-- index.html
    |   +-- Ahmed.class
0
source

All Articles