我是编程新手。获取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