Note that there are some explanatory texts on larger screens.

plurals
  1. POPositions in ArrayLists
    primarykey
    data
    text
    <p>My code is not working like I thought it should. The list <code>listColumn0</code> contains the X and Y positions for 8 sprite objects on the screen. When I touch on one of them I check witch sprite object that match that X and Y position and then remove it from the list. But the strange thing is that this only works if I first touch on the last sprite object with index 7 and if I then continue with sprite object with index 6 and so on.</p> <p>If I click on, let's say, sprite object with index 3 or some of the other besides the last, then the app is closing down! Why this? Can someone see what I have done wrong or can I do this in a better way? Is there a better way to detect/match which sprite object I have touched?</p> <pre><code> String size = Integer.toString(listColumn0.size()); // Check all lists for(ColorObject colorObject: listColumn0) { if(x &gt; (colorObject.xPosition - colorObject.radius) &amp;&amp; x &lt; (colorObject.xPosition + colorObject.radius) &amp;&amp; y &gt; (colorObject.yPosition - colorObject.radius) &amp;&amp; y &lt; (colorObject.yPosition + colorObject.radius)) { String colorCode = Integer.toString(colorObject.color); String index = Integer.toString(listColumn0.indexOf(colorObject)); Log.i("Test","Match!! " + size + " Color: " + colorCode + "ID: " + index); listColumn0.remove(listColumn0.indexOf(colorObject)); } } </code></pre> <p><strong>EDIT:</strong></p> <p>Eror message from LogCat:</p> <pre><code>05-22 07:08:55.482: W/dalvikvm(1444): threadid=12: thread exiting with uncaught exception (group=0x40a13300) 05-22 07:08:55.482: E/AndroidRuntime(1444): FATAL EXCEPTION: Thread-124 05-22 07:08:55.482: E/AndroidRuntime(1444): java.util.ConcurrentModificationException 05-22 07:08:55.482: E/AndroidRuntime(1444): at java.util.ArrayList$ArrayListIterator.next(ArrayList.java:569) 05-22 07:08:55.482: E/AndroidRuntime(1444): at com.test.game.ColorObjectManager.checkPosition(ColorObjectManager.java:164) 05-22 07:08:55.482: E/AndroidRuntime(1444): at com.test.game.GameLoop.run(GameLoop.java:190) 05-22 07:08:55.482: E/AndroidRuntime(1444): at java.lang.Thread.run(Thread.java:856) 05-22 07:13:55.753: I/Process(1444): Sending signal. PID: 1444 SIG: 9 </code></pre>
    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.
 

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