下面是代码,运行的时候点击播放,循环,停止时就抛出异常
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.applet.*;
import java.net.*;public class Player extends Frame implements Runnable,ItemListener,ActionListener {
private Thread thread;
private Choice choice;
private URL url;
private AudioClip clip;
private Button playButton,loopButton,stopButton;

private String str;
Player(String ss){
super(ss);
thread=new Thread(this);

choice=new Choice();
choice.add("F:\\JBuilder2007_workspace\\JavaCourse\\QQ幻想主题曲.wav");
choice.add("E:\\my music\\王心凌-第一次爱的人.wav");

playButton=new Button("播放");
loopButton=new Button("循环");
stopButton=new Button("停止");

playButton.addActionListener(this);
loopButton.addActionListener(this);
stopButton.addActionListener(this);

setLayout(new FlowLayout());

add(choice);
add(playButton);
add(loopButton);
add(stopButton);

setBounds(210,60,200,300);
setVisible(true);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
pack();
}
public void itemStateChanged(ItemEvent e){
str=choice.getSelectedItem();
if(!thread.isAlive()){
thread=new Thread();
}
try{
thread.start();
}catch(Exception e1){
System.out.println(""+e1.getMessage());
}
}
public void run(){
try{
File file=new File(str);
url=file.toURL();
clip=Applet.newAudioClip(url);
}catch(Exception e2){
System.out.println(""+e2.getMessage());
}
}
public void actionPerformed(ActionEvent s){
if(s.getSource()==playButton){
clip.play();
}else if(s.getSource()==loopButton){
clip.loop();
}
if(s.getSource()==stopButton){
clip.stop();
}
}
public static void main(String[] args) {
Player player=new Player("Player"); }}
异常:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Player.actionPerformed(Player.java:75)
at java.awt.Button.processActionEvent(Button.java:388)
at java.awt.Button.processEvent(Button.java:356)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)