我正在做一个项目,尝试使用Controller加载文件,然后将其解析为Model,但是,我不确定是否应解析文件本身或路径名。现在,我正在尝试解析文件,但是我得到了NullPointerException,所以我想我只是没有正确地解析它,这是代码。
public class LoadAction extends AbstractAction{
public File loadFile;
public LoadAction() {
}
@Override
public void actionPerformed(ActionEvent e) {
createLoadFrame();
}
public void createLoadFrame() {
JFileChooser fc = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Saved states", "ser");
fc.setAcceptAllFileFilterUsed(false);
fc.addChoosableFileFilter(filter);
fc.showOpenDialog(null);
System.out.println(fc.getSelectedFile());
loadFile = fc.getSelectedFile();
}
public File getLoadFile() {
return loadFile;
}
}
public class SomeOtherClass(){
public void load(){
File fileName = new LoadAction().getLoadFile();
try {
FileInputStream fileIn = new FileInputStream(fileName);
ObjectInputStream in = new ObjectInputStream(fileIn);
}