日期:2014-05-20  浏览次数:20833 次

初学JAVA,求大神指点。谢谢!
发出错误:Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
错误在  : player.play();

代码:import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.swing.JButton;
import javax.swing.JFrame;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.advanced.AdvancedPlayer;


public class AudioFrame extends JFrame {
private JButton palybutton;
private JButton stopbutton;
private AdvancedPlayer player;
public AudioFrame(){
setSize(300,400);
setLayout(new FlowLayout());
try{
player=new AdvancedPlayer(new FileInputStream("music/music。mp3"));
}
catch(FileNotFoundException e ){
   e.getStackTrace();
}
catch(JavaLayerException e ){
e.printStackTrace();
}
palybutton = new JButton("PLAY");
palybutton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
try{
   player.play();
}catch(JavaLayerException e1){
e1.printStackTrace();
}
}});
stopbutton = new JButton("STOP");
stopbutton.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {
// TODO 自动生成的方法存根
player.stop();
}
});
add(palybutton);
add(stopbutton);
setVisible(true);

}
public static void main(String[]args){
new AudioFrame();
}
}
JAVA

------解决方案--------------------
player=new AdvancedPlayer(new FileInputStream("music/music。mp3"));
player没有被初始化
先改成英文点试一下 music.mp3
------解决方案--------------------
"music/music。mp3"));
"music/music.mp3"));
------解决方案--------------------
@Override
public void actionPerformed(ActionEvent e) {
try{
   player.play();
}catch(JavaLayerException e1){
e1.printStackTrace();
}
}}

---------------------------------------------------
player没有初始化 ,报空指针异常

@Override
public void actionPerformed(ActionEvent e) {
try{
   if  (player == null){
      player = new AdvancedPlayer() ;
   }
   player.play();
}catch(JavaLayerException e1){
e1.printStackTrace();
}
}}
------解决方案--------------------
music/music。mp3-->music/music.mp3 楼主别忘了结贴
------解决方案--------------------
额~~~~一个标点引发的血案.....
("music/music。mp3"))