Note that there are some explanatory texts on larger screens.

plurals
  1. POOdd Java String[] issue, contains value but acts like null when inserting into List<String[]>
    text
    copied!<p>I am having an issue with a String array and trying to add it to a list (List). Below is the code that is used and creating the issue.</p> <p>The program fails on the first run through of the loop and I have verified the input which comes from a CSV using OpenCSV.</p> <pre><code>List&lt;String[]&gt; output = null; String[] temp; for(int i = 0; i &lt; 13; i++) { temp = reader.readNext(); //read next line into temp System.out.println(temp[0]+temp[1]+temp[2]); //temp output temp[2] = String.valueOf((values[i])/100); //assign new value System.out.println(temp[0]+temp[1]+temp[2]); //temp output output.add(temp); } </code></pre> <p>When this code runs the output is.</p> <pre><code>VANCBULLET0.311 VANCBULLET0.308 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Main.updateCSV(Main.java:951) at Main.start(Main.java:863) at Main.access$23(Main.java:853) at Main$23.actionPerformed(Main.java:520) at javax.swing.AbstractButton.fireActionPerformed(Unknown Source) at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source) at javax.swing.DefaultButtonModel.setPressed(Unknown Source) </code></pre> <p>The first two lines are correct and are split up like: temp[0] temp[1] temp[2] VANC BULLET 0.311 VANC BULLET 0.308</p> <p>The issue is (like the error reads) at: </p> <pre><code>output.add(temp); </code></pre> <p>The documentation reads:</p> <pre><code>NullPointerException - if the specified element is null and this list does not permit null elements </code></pre> <p>but as you can see from my output (the second line) the array "temp" is not null, it contains "VANC BULLET 0.308" in each element respectively.</p> <p>I'm stumped. Does anyone have an idea or see something I have failed to see?</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload