我正在尝试在java中反序列化单个变量,但是在转换值时似乎遇到了问题:
public void loadGrid(Sudoku testGrid) {
try {
FileInputStream fileIn = new FileInputStream(System.getProperty("user.home") + "\tmp\grid.grd");
ObjectInputStream in = new ObjectInputStream(fileIn);
testGrid.sudokuGrid = (Sudoku.sudokuGrid) in.readObject();
in.close();
fileIn.close();
} catch(IOException i) {
i.printStackTrace();
} catch(ClassNotFoundException c) {
c.printStackTrace();
}
}
数独是一个包含 ArrayList 变量的 ArrayList 的类。我遇到:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Sudoku.sudokuGrid cannot be resolved to a type
您需要
转换为Sudoku.sudokuGrid
的类型,而不是sudokuGrid
字段本身:
testGrid.sudokuGrid = (ArrayList<ArrayList<SomeType>>) in.readObject();