首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Appletviewer抛出java.lang.NoClassDefFoundError异常

Appletviewer抛出java.lang.NoClassDefFoundError异常
EN

Stack Overflow用户
提问于 2015-07-07 15:41:20
回答 1查看 1.9K关注 0票数 2

我想在applet中运行appletviewer。我的项目目录有以下结构:

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

AppletDocumentLoader是我的项目,然后在/bin/com/examples/ti中有3个类文件和HTML。都在同一个目录里。

我的src课程

代码语言:javascript
复制
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文件

代码语言:javascript
复制
<!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>

我所犯的错误是:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-07 15:43:06

applet标记的代码参数应该是Java类的全名,因此是com.examples.ti.Applet。请参阅Applet code tags and class files

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31273280

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档