当我尝试在 Applet 上加载图像或声音时遇到问题。我使用 LWJGL for applet 和 Slick2d 来加载图像/声音。但是当我用 Netbeans 启动小程序时,没有问题......我用来加载声音的代码:
public class Files {
public static Audio sound;
public static void load() {
try {
sound = AudioLoader.getAudio("WAV", ResourceLoader.getResourceAsStream("/snd/Tir1-16b.wav"));
} catch (IOException ex) {
Logger.getLogger(Files.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("loaded with success !");
}
}
还有 HTML 页面:
<applet code="org.lwjgl.util.applet.AppletLoader" archive="lwjgl_util_applet.jar" codebase="." width="800" height="600">
<!-- The following tags are mandatory -->
<!-- Name of Applet, will be used as name of directory it is saved in, and will uniquely identify it in cache -->
<param name="al_title" value="appletloadertest">
<!-- Main Applet Class -->
<param name="al_main" value="myapps.MyApps">
<!-- List of Jars to add to classpath -->
<param name="al_jars" value="lwjgl_applet.jar, lwjgl.jar, jinput.jar, lwjgl_util.jar MyApps.jar">
<!-- signed windows natives jar in a jar -->
<param name="al_windows" value="windows_natives.jar">
<!-- signed linux natives jar in a jar -->
<param name="al_linux" value="linux_natives.jar">
<!-- signed mac osx natives jar in a jar -->
<param name="al_mac" value="macosx_natives.jar">
<!-- signed solaris natives jar in a jar -->
<param name="al_solaris" value="solaris_natives.jar">
<!-- Tags under here are optional -->
<!-- whether to use cache - defaults to true -->
<!-- <param name="al_cache" value="true"> -->
<!-- Version of Applet (case insensitive String), applet files not redownloaded if same version already in cache -->
<!-- <param name="al_version" value="0.1"> -->
<!-- Specify the minimum JRE version required by your applet, defaults to "1.5" -->
<!-- <param name="al_min_jre" value="1.6"> -->
<!-- background color to paint with, defaults to white -->
<!-- <param name="boxbgcolor" value="#000000"> -->
<!-- foreground color to paint with, defaults to black -->
<!-- <param name="boxfgcolor" value="#ffffff"> -->
<!-- logo to paint while loading, will be centered, defaults to "appletlogo.gif" -->
<!-- <param name="al_logo" value="appletlogo.gif"> -->
<!-- progressbar to paint while loading. Will be painted on top of logo, width clipped to percentage done, defaults to "appletprogress.gif" -->
<!-- <param name="al_progressbar" value="appletprogress.gif"> -->
<!-- whether to run in debug mode -->
<!-- <param name="al_debug" value="true"> -->
<!-- whether to prepend host to cache path - defaults to true -->
<!-- <param name="al_prepend_host" value="true"> -->
<param name="separate_jvm" value="true">
</applet>
当我使用小程序启动 HTML 页面时,控制台日志会显示以下内容:
null
java.lang.reflect.InvocationTargetException
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at java.awt.EventQueue.invokeAndWait(Unknown Source)
at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:906)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: org/newdawn/slick/util/ResourceLoader
at myapps.Files.load(Files.java:24)
at myapps.MyApps.init(MyApps.java:32)
at org.lwjgl.util.applet.AppletLoader.switchApplet(AppletLoader.java:1330)
at org.lwjgl.util.applet.AppletLoader$2.run(AppletLoader.java:909)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(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: org.newdawn.slick.util.ResourceLoader
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 18 more
null 当然意味着变量 Audio 为空。这也意味着可能找不到该文件...所以我尝试将目录“snd”和“sprites”放在小程序目录以及小程序的 .jar 上,但没有任何反应...
任何人都可以帮助我吗?我搜索了很多时间试图在许多论坛上找到这种问题,但没有人帮助我......
非常感谢 !