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();
}