CODE
File directory = null; // init to null
try {
FileInputStream fis = new FileInputStream("LastCall.tmp");
ObjectInputStream ois = new ObjectInputStream(fis);
directory = (File) ois.readObject();
ois.close();
}
catch (Exception e) { // OK no file or cast error <------- Exception instead of //IOException
}
You need to initialize directory to null.
That way you tell the Java compiler "I know what I am doing"
As the try block might fail opening the FileInputStream nothing garantees that directory will be initialized so the Java compiler will issue an error "directory might not be initialized"
And you are right you don't need to declare another JFileChooser, you can use the existing one
But I don't understand that:
CODE
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG, GIF, & PNG Images", "jpg", "gif", "png");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
You should try to open the file before doing that to get what was the directory of the last session....
If you always start from fresh every time what it the use of the file ?
If you just want to remember it from the last time you clicked the button (or whatever fires your actionPerformed() no need to save the directory in a file, just keep it in an instance variable "directory"
I though you wanted to remember the last directory accessed from session to session...