2013-04-01 54 views
0

我嘗試在Applet上加載圖像或聲音時出現問題。我使用LWJGL applet和Slick2d加載圖像/聲音。 但是,當我啓動與Netbeans的小程序,有沒有問題...... 還有就是我用來加載聲音的代碼:使用LWJGL/Slick2d小程序加載圖像/聲音

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 

空肯定意味着可變音頻爲空。這也意味着該文件可能沒有找到...所以我試圖把目錄「snd」和「sprites」放在applet目錄中,並且也放在我的applet的.jar上,但沒有任何反應......

任何人都可以幫我嗎?我搜索了很多時間嘗試在許多論壇上也發現這種問題,但沒有人幫助我...

非常感謝!

+0

'NoClassDefFoundError'首先修復。什麼Jar是'ResourceLoader'位於? –

回答

0

感謝您的回答。 我在我的HTML頁面中加入「slick.jar」像如下固定的NoClassDefFoundError問題:

<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 

而簽名者已經工作,因爲現在我可以看到文件「KEY.RSA」和「KEY。 SF「放在MyApps.jar的META-INF上。 但還是這裏的問題...

我需要一些幫助,我只是不明白這個問題...

謝謝!

+0

*「但現在我有另一個問題:」*這應該是(研究小程序和文件/ URL,可能)一個新的問題。 –

+0

嗨,是的,這是另一個問題,但它仍然是加載圖像或聲音的問題。我搜索了很多關於這個,但我真的沒有發現任何東西......大家都說這是因爲applet沒有簽名,但我的簽名。 – AntiRGen

+0

這一個應該是關於NCDFE。我沒有花費更多的時間。 –

相關問題