4
當我嘗試將列表轉換回數組時,我收到了NPE。 我調試通過,發現我的列表正在獲得一個額外的值爲null。NullPointerException當試圖將列表轉換回數組時
爲什麼會發生,更重要的是我該如何解決這個問題?
List<String> attrList = new LinkedList<String>(Arrays.asList(attrArray))
//I loop through and remove unnecessary elements
attrArray = attrList.toArray(attrArray);
//next line uses attrArray and is throwing NPE.
Here's what I found through debugging,
attrList = [1, 2, 3]
attrArray = [1, 2, 3, null]
什麼是'attributeList'?你抱怨說它包含一個'null',但你還沒有發佈任何引用它的代碼。 – ruakh 2013-02-10 22:03:27
是我還是一些線是多餘的? 'attrArray = attrList.toArray(attrArray);'例如。我懷疑這是實際的代碼。 – 2013-02-10 22:04:04
@LewsTherin。所以,你錯過了最後一行呀? – 2013-02-10 22:05:10