需要帮助我的问题,我需要将3个数组合并成一个多维数组。但我总是遇到错误,其中一些值返回null。在第一阵列(字符串[] []数据集)中的数据是:组合2字符串[] []和1字符串[]变成一个字符串[] []
弦乐[] [] predictiondata001200700001 70 70 70 55 70
001200700002 70 70 60 60 60
001200700003 85 85 85 60 85
001200700004 60 70 85 70 85
001200700005 70 60 60 60 85
数据是:
15 74.25 64.25 64.25 64.25 89.25
14 74.25 64.25 64.25 64.25 89.25
和手段[]为:
String[]Means={"Means","0","0","0","0","0"};
所以这里是到目前为止我的代码和错误输出:
public void hashtree(String[][]dataset, String[][]predictiondata){
//======fetch data from database then add 1 morre row for calculation
String[]Means={"Means","0","0","0","0","0"};
int heightofarray = (dataset.length)+(predictiondata.length)+(Means.length);
int lengthofarray=(dataset[0].length);
System.out.println("heightofarray: "+heightofarray+" lengthofarray: "+lengthofarray);
String[][]toCalculate = new String[heightofarray][lengthofarray];
for(int a=0;a<dataset.length;a++){
for(int b=0;b<dataset[0].length;b++){
toCalculate[a][b]=dataset[a][b];
}
}
for(int a=0;a<predictiondata.length;a++){
for(int b=0;b<predictiondata[0].length;b++){
toCalculate[(dataset.length)+a][b]=predictiondata[a][b];
}
}
for(int a=0;a<Means.length;a++){
toCalculate[heightofarray-1][a]=Means[a];
}
System.out.println("should print String[][]toCalculate");
for(int a=0;a<toCalculate.length;a++){
for(int b=0;b<toCalculate[0].length;b++){
System.out.print(toCalculate[a][b]+"\t");
}System.out.println("");
}
用于新组合的阵列的顺序(字符串[] [] toCalculate)是:
字符串[] []的数据集
字符串[] [] predictiondata
字符串[]意指
但是,无论我总是得到输出
System.out.println("should print String[][]toCalculate");
001200700001 70 70 70 55 70
001200700002 70 70 60 60 60
001200700003 85 85 85 60 85
001200700004 60 70 85 70 85
001200700005 70 60 60 60 85
15 74.25 64.25 64.25 64.25 89.25
14 74.25 64.25 64.25 64.25 89.25
null null null null null null
null null null null null null
null null null null null null
Exception in thread "main" java.lang.NullPointerException
null null null null null null
null null null null null null
Means 0 0 0 0 0
非常感谢您为解决
非常感谢你,它通过将Means的值改变为这种计算方式起作用。 – charcoalite 2012-03-17 09:24:17