尝试将列表转换回数组时,我得到了 NPE。我调试了一遍,发现我的列表得到了一个额外的值为空的值。
为什么会发生,更重要的是我该如何解决这个问题?
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]