我真的很困惑:我只是試圖將ArrayList
中的每個對象的名稱添加到另一個ArrayList
。這是一個nullpointerexception?
for (int i = 0; i < availableParts.size(); i++) {
for (int j = 0; j < namesOfIngredients.size(); j++){
if (availableParts.get(i).getName() != namesOfParts.get(j)){
namesOfParts.add(availableParts.get(i).getName());
}
}//middle if statement makes sure there are no repeats
}
編輯:我知道namesOfIngredients爲null。不過,我需要它開始空 - 這是我如何複製名稱。這可以不這樣做嗎?
你得到一個NPE哪條線路? – Saket
內循環(與j的一個)。 這可能有助於提及namesOfIngredients之前爲空 – varatis
有人可能想要使用調試器? – Romain