Ich speichere zwei Objekte ab. Obere Methode.
In der unteren Lade ich sie wieder. Wie kann ich dort den unchecked Cast Error umgehen?
In der unteren Lade ich sie wieder. Wie kann ich dort den unchecked Cast Error umgehen?
Code:
public boolean saveSudoku(SudokuField sudokuToSave, Stack<FieldChangedEvent> undo) {
if (fileChooser.showSaveDialog(modalComponent.getParent()) != JFileChooser.CANCEL_OPTION) {
File fileName = fileChooser.getSelectedFile();
if ( fileName == null || fileName.getName().equals("") ) {
showError("Invalid File Type");
} else {
try {
if (fileName.toString().indexOf(".sud") == -1)
output = new ObjectOutputStream(new FileOutputStream(fileName.toString()+".sud"));
else
output = new ObjectOutputStream(new FileOutputStream(fileName.toString()));
output.writeObject(sudokuToSave);
output.writeObject(undo);
output.close();
return true;
} catch (IOException ioEx) {
showError("Error Writing File");
}
}
}
return false;
}
public SudokuField loadSudoku() {
if (fileChooser.showOpenDialog(modalComponent.getParent()) != JFileChooser.CANCEL_OPTION) {
File fileName = fileChooser.getSelectedFile();
if ( fileName == null || fileName.getName().equals("") || fileName.getName().indexOf(".sud") == -1) {
showError("Invalid File Type");
} else {
try {
input = new ObjectInputStream(new FileInputStream(fileName.toString()));
SudokuField field = (SudokuField)input.readObject();
Stack<FieldChangedEvent> stack = (Stack<FieldChangedEvent>)input.readObject(); //unchecked cast error
return field;
} catch (IOException ioEx) {
showError("Error Reading File");
} catch (ClassNotFoundException cNFEx) {
showError("No such File");
}
}
}
return null;
}