读书人

fileChooser.showOpenDialo不选择文件

发布时间: 2014-01-26 14:37:04 作者: rapoo

fileChooser.showOpenDialo不选择文件时报空指针异常

class LoadFileButtonAction implements ActionListener {

public void actionPerformed(ActionEvent event) {
System.out.println("LoadFileButtonAction");
fileChooser.showOpenDialog(sendPanel);
String filePath = null;
if(fileChooser.getSelectedFile().getPath()!= null)
filePath = fileChooser.getSelectedFile().getPath();
System.out.println("FilePaht = " + filePath);


这段程序要怎么改呀

------解决方法--------------------------------------------------------
String filePath = null;
改成
String filePath = "";
试试

------解决方法--------------------------------------------------------
String filePath="" ;
JFileChooser chooser=new JFileChooser() ;
int result=chooser.showOpenDialog(null) ;
if(result==JFileChooser.APPROVE_OPTION){
filePath = fileChooser.getSelectedFile().getPath();
}

        

读书人网 >Java Exception

热点推荐