簡體   English   中英

Appletviewer引發java.lang.NoClassDefFoundError異常

[英]Appletviewer throws java.lang.NoClassDefFoundError exception

我想在appletviewer運行一個applet 我的項目目錄具有以下結構:

/home/sanctus/workspace/AppletDocumentLoader/bin/com/examples/ti

AppletDocumentLoader是我的項目,然后在/bin/com/examples/ti有3個類文件和HTML文件,即。 全部在同一個目錄中。

我的src班

package com.examples.ti;
import java.applet.AppletContext;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

public class Applet extends JApplet {

    private static final long serialVersionUID = -8756947240188460854L;


    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    JLabel label = new JLabel("Hello World");
                    add(label);
                    JButton openDocument = new JButton();
                    openDocument.setText("Button");
                    openDocument.addActionListener(new ActionListener() {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            System.out.println("BUTTON CLICKED");
                            AppletContext appletContext = getAppletContext();
                            try {
                                appletContext
                                        .showDocument(
                                                new URL(
                                                        "http://www.google.com"),
                                                "_self");
                            } catch (MalformedURLException e1) {
                                e1.printStackTrace();
                            }

                        }
                    });
                    add(openDocument);
                }
            });
        } catch (InvocationTargetException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

我的HTML檔案

<!DOCTYPE html>
<html>
<head>
  <title>Hi there</title>
</head>
<body>
  This is a page
  a simple page
</body>
<applet code="Applet.class" 
        archive="Applet.jar"
        width=350 height=350>
</applet>
</html>

我得到的錯誤是:

sanctus@sanctus-desktop:~$ appletviewer '/home/sanctus/workspace/AppletDocumentLoader/bin/com/examples/ti/index.html' 
java.lang.NoClassDefFoundError: Applet (wrong name: com/examples/ti/Applet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:217)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:152)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:626)
    at sun.applet.AppletPanel.createApplet(AppletPanel.java:799)
    at sun.applet.AppletPanel.runLoader(AppletPanel.java:728)
    at sun.applet.AppletPanel.run(AppletPanel.java:378)
    at java.lang.Thread.run(Thread.java:745)

applet標記的code參數應為Java類的全名,即com.examples.ti.Applet 查看Applet代碼標簽和類文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM