为反序列化转换 ArrayList class 个变量
Casting ArrayList class variables for deserialization
我正在尝试反序列化 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();
}
}
Sudoku 是一个 class 包含 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();
我正在尝试反序列化 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();
}
}
Sudoku 是一个 class 包含 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();