需要幫助我的問題,我需要將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