我想將字符串數組中的值存儲到另一個字符串數組中。但是,我得到下面的代碼的「NullPointerException」錯誤。 「imagesSelected」是一個字符串數組,裏面存儲着值。但是當我想在substring之後將它移動到另一個字符串數組時,我得到錯誤。我相信是因爲最後一行代碼。我不知道如何使它工作。將值存儲到字符串數組中
String[] imageLocation;
if(imagesSelected.length >0){
for(int i=0;i<imagesSelected.length;i++){
int start = imagesSelected[i].indexOf("WB/");
imageLocation[i] = imagesSelected[i].substring(start + 3);
}
}
您需要初始化'imageLocation'陣列到合適的大小。 – gsingh2011
add print stack trace –
你沒有初始化數組的字符串''String [] imageLocation = new String [x];''是嗎? – 2012-12-12 04:34:15