Array list remove error

Discussion in 'Plugin Development' started by kulersh, Aug 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    kulersh

    This show me error.

    For example
    Code:
    public static List<String> mgSigns = new ArrayList<String>();
    Code:
    if(cfg.mgSigns.contains(list)){
      cfg.mgSigns.remove(list);  //<-----------    Correcty this show me error, not slashes, but command!
    }
     
  2. Offline

    SuperOmegaCow

  3. Code:java
    1. public static List<String> mgSigns = new ArrayList<String>();

    Needs to be:
    Code:java
    1. public ArrayList<String> mgSigns = new ArrayList<String>();
     
  4. Offline

    hatstand

    Wrong.
     
  5. You say wrong but don't provide a reason, you're not helping anyone, so if you can't say why then please, don't say I'm wrong.


    EDIT: Also, OP. Can you show us your "list" variable. I'm assuming it's a list. So for that you need to go through a For loop.
    Code:java
    1. for(String s : list){
    2.  
    3. cfg.mgSigns.remove(s);
    4.  
    5. }
     
  6. Offline

    SuperOmegaCow

    Mersenne Twister hatstand since he did not provide an error I assume he did:
    Player player = blablabla;
    When it needs to be:
    String player = blablabla;
     
  7. Offline

    hatstand

    ArrayList implements the List interface, therefore you can assign an ArrayList to a List variable. Using the specific list implementation as the variable type provides zero benefit, and won't fix his problem.

    If I had to guess, his error is because contains() takes an Object, whilst remove() takes (in this case) a String. If his list variable is a list, he wants to be using containsAll() and removeAll(). So while your loop would work, there are already methods to do that for you.
     
  8. Offline

    kulersh

    i still have error but i dont know why

    Code:
    22.08 19:01:46 [Server] INFO at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    22.08 19:01:46 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    22.08 19:01:46 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    22.08 19:01:46 [Server] INFO at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    22.08 19:01:46 [Server] INFO at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:522)
    22.08 19:01:46 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
    22.08 19:01:46 [Server] INFO at org.bukkit.craftbukkit.v1_6_R2.scheduler.CraftTask.run(CraftTask.java:53)
    22.08 19:01:46 [Server] INFO at me.kulers.multigame.main.main$1.run(main.java:213)
    22.08 19:01:46 [Server] INFO at me.kulers.multigame.bowspleef.main.startGameIfEnaughtPlayers(main.java:324)
    22.08 19:01:46 [Server] INFO at java.util.HashMap$KeyIterator.next(HashMap.java:874)
    22.08 19:01:46 [Server] INFO at java.util.HashMap$HashIterator.nextEntry(HashMap.java:839)
    22.08 19:01:46 [Server] INFO java.util.ConcurrentModificationException
    22.08 19:01:46 [Server] WARNING Task #91 for MultiGame v1.0 generated an exception

    Fixed: ap needed to change to HashMap
     
Thread Status:
Not open for further replies.

Share This Page