您好我正在尝试将2D数组存储在另一个2D数组中,以便检查哪些变量不存在。(这对我来说很复杂)
然而,当我这样做时,我得到一个“空指针异常”
try {
File file = new File(FILENAME);
Scanner inputFile = new Scanner(file);
// Read the number of Rows and Columns first
numberOfRows = inputFile.nextInt();
numberOfCols = inputFile.nextInt();
data = new int[numberOfRows][numberOfCols];
// Complete the reading of data from the file - see Lecture Notes
for (int row = 0; row < numberOfRows; row++)
{
for (int col = 0; col < numberOfCols; col++)
{
data[row][col] = inputFile.nextInt();
check[row][col] = data[row][col];
}
}
inputFile.close();
}
catch (FileNotFoundException ex) {
System.out.println("Error reading data from " + FILENAME + " Exception = " + ex.getMessage());
}
谢谢你的帮助
答案 0 :(得分:0)
NullPointerException 所以请再次检查你的代码,可能是2个变量值 numberOfRows,numberOfCols