I am using Java to make a game, but I can't use the interrupt() function. It says the interrupt() function is undefined.
Here is the code. What should I do to solve this problem?
p.s. I think somebody says that the error is because of (skip), but I think you didn't catch the meaning of the question.
I found the error. Thanks for the comment!
package beat_the_beat_1_0;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class Music {
private Player player;
private boolean isLoop;
private File file;
private FileInputStream fis;
private BufferedInputStream bis;
public Music(String name, boolean isLoop) {
try {
this.isLoop = isLoop;
file = new File(Main.class.getResource("../music/" + name).toURI());
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
player = new Player(bis);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public int getTime() {
if(player == null)
return 0;
return player.getPosition();
}
public void close() {
isLoop = false;
player.close();
this.interrupt(); // Here is the error.
}
@Override
public void run() {
try {
do {
player.play();
fis = new FileInputStream(file);
bis = new BufferedInputStream(fis);
player = new Player(bis);
} while(isLoop);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}