Note that there are some explanatory texts on larger screens.

plurals
  1. POStrings visually identical but not matching; list iterator exception
    primarykey
    data
    text
    <p>I'm new here, so I'm not sure if it's ok to have 2 questions in the same post, so if I'm not supposed to just tell me (nicely!) and I'll change it to one question here and start another post elsewhere.</p> <p>First problem:</p> <p>Below on lines 5-8 I'm referring to two strings that I need to compare to see if they are the same. I'm using the <code>getUserInput()</code> method to get a response from the user at terminal and then I'm having it go ahead and print both strings so that I can visually inspect them, and they are coming up the same. However, the <code>if</code> section that is supposed to run when they are the same never runs and then the <code>else</code> section always does. </p> <p>Second problem:</p> <p>In the <code>else</code> section right below, whenever the <code>currentChump</code>'s health is reduced to <code>&lt; 1</code>, I get a block of exceptions that I've never seen before and don't know what do do about.</p> <p>Here is my code, and then below I will paste the exception:</p> <pre><code>for (Chump currentChump : chumpArray) { System.out.println(" "); String playerChoice = helper.getUserInput( "Type the name of the Weapon that you wish to use."); System.out.println(playerChoice); System.out.println(currentChump.getWeakness().toLowerCase()); if (currentChump.getWeakness().toLowerCase() == playerChoice) { chumpArray.remove(currentChump); } // END IF else { while (PlayerIsAlive &amp;&amp; currentChump.getHealth() &gt; 0) { int damage = (int) Math.floor((Math.random() * 6) + 1); System.out.println(currentChump.getName() + " has " + currentChump.getHealth() + "health remaining."); currentChump.setHealth(currentChump.getHealth() - damage); System.out.println("You hit the enemy for " + damage + " points of damage."); System.out.println(currentChump.getName() + " has " + currentChump.getHealth() + " health remaining."); System.out.println(" "); if (currentChump.getHealth() &lt; 1) { chumpArray.remove(currentChump); } // END IF else { int damage2 = (int) Math.floor((Math.random() * 4) + 1); player.setHealth(player.getHealth() - damage2); if (player.getHealth() &lt; 1) { PlayerIsAlive = false; } // END IF } // END WHILE } // END ELSE } // END ELSE } // END FOR </code></pre> <p>exception:</p> <pre><code>Exception in thread "main" java.util.ConcurrentModificationException at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372) at java.util.AbstractList$Itr.next(AbstractList.java:343) at ArenaGameCopy.startPlaying(ArenaGameCopy.java:87) at ArenaGameCopy.main(ArenaGameCopy.java:168) </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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