我正在上在线课程,我偶尔会挂断电话,因为课程是半以 Windows 为中心的。目前我有一个 java 小程序,我正在尝试在其中播放音频剪辑。我正在使用 Idea Intellij,并将音频文件放在与类文件相同的位置。我还更新了idea用来运行小程序的策略文件,但无论我做什么,它似乎都找不到音频文件。我有 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)