无法解析符号 'getAudioInputStream'
Cannot resolve symbol 'getAudioInputStream'
".getAudioInputStream(file)" 给出错误“无法解析符号”(IDE Intellij,java 8)
我尝试了文件 > 使挑战无效/重新启动...中的解决方案,但它不起作用
package com.Main;
import javax.sound.sampled.Clip;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class SoundEffect {
private String filepath;
private Clip clip;
public SoundEffect(String filepath) {
this.filepath = filepath;
try {
File file = new File(filepath);
AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(sound);
}
catch (Exception e) { e.printStackTrace(); }
}
public void play() {
clip.start();
}
}
AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
您不想创建对象的实例。您想调用 class.
的静态方法
你不需要“新”。
代码应该是:
//AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
AudioInputStream sound = AudioSystem.getAudioInputStream(file);
".getAudioInputStream(file)" 给出错误“无法解析符号”(IDE Intellij,java 8)
我尝试了文件 > 使挑战无效/重新启动...中的解决方案,但它不起作用
package com.Main;
import javax.sound.sampled.Clip;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
public class SoundEffect {
private String filepath;
private Clip clip;
public SoundEffect(String filepath) {
this.filepath = filepath;
try {
File file = new File(filepath);
AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
clip = AudioSystem.getClip();
clip.open(sound);
}
catch (Exception e) { e.printStackTrace(); }
}
public void play() {
clip.start();
}
}
AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
您不想创建对象的实例。您想调用 class.
的静态方法你不需要“新”。
代码应该是:
//AudioInputStream sound = new AudioSystem.getAudioInputStream(file);
AudioInputStream sound = AudioSystem.getAudioInputStream(file);