Note that there are some explanatory texts on larger screens.

plurals
  1. PONullpointer exception when adding to list
    primarykey
    data
    text
    <p>I am trying to iterate through a list of objects to figure out which ones are fighting each other. I am using the <code>checkedGladiators</code> list as something to compare against to prevent it from checking gladiators already assigned to a combat, as each <code>s</code> that isn't assigned already will build their entire combat around them. Currently I get a <code>NullPointerException</code>, so I used some test text to figure that it was happening right at <code>listContains(checkedGladiators,s)</code>. I added the part before it. NOW the problem is happening between "Null" and "Null Changed" as well, which makes no sense to me. </p> <pre><code>for (Gladiator s : gladiators){ if (checkedGladiators == null) { System.out.println("Null"); combat1.add(s); checkedGladiators.add(s); System.out.println("Null Changed"); } if (listContains(checkedGladiators,s)) { // if gladiator is already in a combat do nothing } else { // if he isn't } </code></pre> <p>}</p> <p>listContains class:</p> <pre><code>public boolean listContains(List&lt;Gladiator&gt; List, Gladiator search) { for (Gladiator p : List) { if (p.equals(search)) { return true; } } return false; } </code></pre> <p>Does anyone know why this would occur? Thanks</p> <p>Edit1:</p> <pre><code>public class Ai { private List&lt;Gladiator&gt; gladiators; private List&lt;List&lt;Gladiator&gt;&gt; combatsList; private List&lt;Gladiator&gt; checkedGladiators; private List&lt;Gladiator&gt; combat1; private List&lt;Gladiator&gt; combat2; private List&lt;Gladiator&gt; combat3; private List&lt;Gladiator&gt; combat4; private List&lt;Gladiator&gt; combat5; private List&lt;Gladiator&gt; combat6; private List&lt;Gladiator&gt; combat7; private List&lt;Gladiator&gt; combat8; private List&lt;Gladiator&gt; guardList; private List&lt;Gladiator&gt; advanceList; private List&lt;Gladiator&gt; retreatList; int totalCombats = 0; // total combats going on </code></pre> <p>I have initialized the list variable in the class already.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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