我的代碼有問題,因爲當我嘗試將字符串從arraylist
分配給array
時,它會拋出NullPointerException
。將ArrayList中的字符串分配給Java數組時,會出現NullPointerException
String[][] data = new String[idList.size()][];
for(int i = 1; i<=idList.size(); i++) {
data[i][0] = idList.get(i);
data[i][1] = nameList.get(i);
data[i][2] = hList.get(i);
data[i][3] = sList.get(i);
data[i][4] = fList.get(i);
data[i][5] = mList.get(i);
data[i][6] = osList.get(i);
data[i][7] = tsList.get(i);
data[i][8] = podList.get(i);
data[i][9] = pacList.get(i);
}
有人可以告訴我如何解決這個問題嗎?
在您的調試器中,您將能夠看到'data [0]'爲'null'。我建議你初始化它們。 –