在Web应用程序中加载applet时出错

时间:2011-01-14 20:51:32

标签: applet

我想在网络应用程序上运行我的applet,但是我得到了一些错误,我在下面提到请帮助我摆脱这个问题

Java Plug-in 1.7.0
Using JRE version 1.7.0-ea-b116 Java HotSpot(TM) Client VM
User home directory = C:\Users\HONEY
----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------


java.lang.RuntimeException: java.lang.NoClassDefFoundError: mp3$1
 at sun.plugin2.applet.Plugin2Manager.createApplet(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: mp3$1
 at mp3.<init>(mp3.java:93)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
 at java.lang.reflect.Constructor.newInstance(Unknown Source)
 at java.lang.Class.newInstance0(Unknown Source)
 at java.lang.Class.newInstance(Unknown Source)
 at sun.plugin2.applet.Plugin2Manager$12.run(Unknown Source)
 at java.awt.event.InvocationEvent.dispatch(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: mp3$1
 at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
 at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 ... 16 more
Caused by: java.io.IOException: open HTTP connection failed:http://viscous10.webng.com/mp3/mp3$1.class
 at sun.plugin2.applet.Applet2ClassLoader.getBytes(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader.access$000(Unknown Source)
 at sun.plugin2.applet.Applet2ClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 ... 21 more
Exception: java.lang.RuntimeException: java.lang.NoClassDefFoundError: mp3$1

但只有在我运行带有事件的applet时才会发生 在简单的小程序中,我从未发生过

2 个答案:

答案 0 :(得分:0)

此错误表示Java运行时无法找到mp3类的匿名内部类的.class文件。匿名内部类名为OuterClass $ 1,OuterClass $ 2,OuterClass $ 3,依此类推。匿名内部类的定义示例:

  button1.addActionListener(
     new java.awt.event.ActionListener()
     {
        public void actionPerformed(java.awt.event.ActionEvent e)
        {
           // do something
        }
     }
  );

由于您似乎在使用内部类,请注意您的mp3.java源文件会创建各种.class文件,并确保所有这些.class文件都可用于运行时环境(通过复制或添加它们.jar文件等。)

答案 1 :(得分:0)

在网络浏览器上运行applet

  1. 编写java代码在java上运行应用程序
  2. 使用cmd提示创建类文件
  3. 提供正确的路径并在cmd提示符下运行您的java文件以创建类文件
  4. 使html文件在其中添加applet代码<applet code=file.class archive =file.zip/jar></applet>
  5. 从控制面板启用了java控制台
  6. 运行html文件并刷新窗口
  7. 注意:确保具有相同名称的类文件,html文件,zip或jar文件以避免混淆