日期:2014-05-20  浏览次数:20785 次

出现Exception in thread "main" java.lang.NullPointerException求指教,急急急
public class txtTOarray {
public static void main(String[] args){
try {
File file = new File("D:\\array1.txt");
BufferedReader in;
FileReader fr=new FileReader(file);
in = new BufferedReader(fr);
int n=200;
int[][] arr=new int[n][];
String line=""; //一行数据
int row=0;
try {
while((line = in.readLine())!= null){
String[] temp = line.split("\t");  
for(int j=0;j<temp.length;j++){
arr[row][j] = Integer.parseInt(temp[j]);//有问题????
}
row++;
}
in.close();
for(int i=0;i<n;i++){
for(int j=0;j<arr[i].length;j++){
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}


------解决方案--------------------
判断temp[j]是否为空
------解决方案--------------------
先定义数组的长度.在String[] temp = line.split("\t"); 这句后加上看看。

arr[row]=new int[temp.length];