我是編程新手。獲取NullPointerException - 如何刪除它?
array [row][col] = line.charAt(col);
^這條線是我在我的代碼中獲得NullPointerException
的地方。如何刪除它?
Scanner in = null;
try {
in = new Scanner(new FileReader("C:\\Documents and Settings\\UserXP\\My Documents\\src\\file.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String line="";
ArrayList<String>arrayList=new ArrayList<String>();
while((line=in.nextLine())!=null) {
arrayList.add(line);
char [][] array = new char [2337][];
for (int row = 0; row<arrayList.size(); row++)
for(int col = 0; col<line.length(); col++) {
array [row][col] = line.charAt(col);
System.out.print(""+ array[row][col]);
}
System.out.println("");
}
//Close the input stream
in.close();
我不知道如何去除這個異常 – user1172026 2012-01-27 12:34:43
爲什麼神奇數字2337? – adarshr 2012-01-27 12:35:06
請將堆棧跟蹤添加到您的問題以及 – fmucar 2012-01-27 12:35:52