0

当我尝试在 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 上,但没有任何反应...

任何人都可以帮助我吗?我搜索了很多时间试图在许多论坛上找到这种问题,但没有人帮助我......

非常感谢 !

4

1 回答 1

0

感谢您的回答。我NoClassDefFoundError通过在我的 html 页面中添加“slick.jar”来解决问题,如下所示:

<param name="al_jars" value="MyApps.jar lwjgl_applet.jar, lwjgl.jar, jinput.jar, lwjgl_util.jar slick.jar">

但现在我有另一个问题:

This occurred while 'Initializing real applet'
access denied ("java.io.FilePermission" ".\snd\Tir1-16b.wav" "read")
java.security.AccessControlException: access denied ("java.io.FilePermission" ".\snd\Tir1-16b.wav" "read")
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.exists(Unknown Source)
    at org.newdawn.slick.util.FileSystemLocation.getResourceAsStream(FileSystemLocation.java:52)
    at org.newdawn.slick.util.ResourceLoader.getResourceAsStream(ResourceLoader.java:61)
    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)

我已经阅读了很多有关此问题的内容,并且尝试使用以下命令对 MyApps.jar 进行签名:

keytool -genkey -keyalg rsa -alias key
keytool -export -alias key -file cert.crt
jarsigner MyApps.jar key

并且签名者已经工作了,因为现在我可以在 MyApps.jar 的 META-INF 上看到文件“KEY.RSA”和“KEY.SF”。但问题仍然在这里...

我需要一些帮助,我只是不明白这个问题......

谢谢 !

于 2013-04-02T18:51:35.933 回答