我正在参加在线课程,我偶尔也会因为课程以半窗口为中心而挂断。目前我有一个java applet,我正在尝试播放音频剪辑。我正在使用Idea Intellij,我将音频文件放在与类文件相同的位置。我还更新了想法用于运行applet的策略文件,但无论我做什么,它似乎都找不到音频文件。我75%肯定这是我用政策文件没想到的东西(唉!),但我无法弄清楚那是什么。我将粘贴代码片段,我的策略文件以及尝试运行时的一些输出。请帮助 - 这是我第二次因为特定于Linux的差异而陷入困境。
格式化打嗝的道歉......
public class MyApplet extends JApplet implements ActionListener
{
JButton play, stop;
AudioClip audioClip;
File myAudioFile;
public void init()
{
play = new JButton("Play");
play.addActionListener(this);
stop = new JButton("Stop");
stop.addActionListener(this
[...took out unnecessary stuff...]
System.out.println("Codebase is: " + getCodeBase());
myAudioFile = new File(getCodeBase().toString()+"desktop-login.ogg");
if(myAudioFile.exists()) {
audioClip = getAudioClip(getCodeBase(), "desktop-login.ogg");
}
else {
System.out.println("Failed to find file:"+ audioClip);
}
}
[...took out unnecessary stuff...]
//------------------POLICY FILE CONTENTS--
grant {
permission java.security.AllPermission;
permission java.net.SocketPermission "*", "accept, connect, listen, resolve";
};
grant codeBase "file:/home/mylogin/IdeaProjects/3RD/Lesson7/soundPlay/out/production/soundPlay/*" {
permission java.util.PropertyPermission "user.home", "read";
};
//--------output (scrubbed a bit - it's failing at the audio clip play part because the audioClip object is null):
Codebase is: file:/home/mylogin/IdeaProjects/3RD/Lesson7/soundPlay/out/production/soundPlay/
Failed to find file:null
Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at MyApplet.actionPerformed(MyApplet.java:48)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995)
答案 0 :(得分:0)
使用这样的文件路径并尝试
file:////home/mylogin/IdeaProjects/3RD/Lesson7/soundPlay/out/production/soundPlay/
答案 1 :(得分:0)