I’m getting a NPE when trying to convert my list back into an array.
I debugged through and found that my list is getting an extra value that is null.
Why is the happening and more importantly how do I fix the issue?
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]
Try replacing
with
I think it will work, because what you have right now is
and JavaDoc of
List#toArray(T[] a)states (highlights by me):