Solved Quick question: HashMaps

Discussion in 'Plugin Development' started by PDKnight, Jul 20, 2015.

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

    PDKnight

    Hey, Bukkit, today I have a really quick question. I wrote this code:
    Code:java
    1. HashMap<String, String> foo = new HashMap<String, String>();
    2. foo.put("1", "2");

    But my Eclipse (I don't know why) don't get it, so it throws 2 errors :D
    Code:
    Syntax error on token(s), misplaced construct(s)
    Syntax error on tokens, delete these tokens
    Screenshot:
    [​IMG]

    What I'm doing wrong?
    Cheers,

    PDKnight
     
  2. Offline

    1Rogue Retired Staff

    You're trying to execute code outside of a method body.
     
  3. Offline

    PDKnight

    @1Rogue
    Awesome, thank you! Anyway, how can I add these default values when I'm creating the "foo" variable?
     
  4. Offline

    SuperSniper

    Dont use strings when using integers inside the list. do <Integer, Integer>
     
  5. Offline

    PDKnight

    @SuperSniper
    :D It was just an example, the code seems pretty different ;)
     
  6. Offline

    1Rogue Retired Staff

    Well, you simply need to execute the code within a method body. A constructor would be one example.
     
    Shortninja66 likes this.
Thread Status:
Not open for further replies.

Share This Page