Hashmap does not contain value?

Discussion in 'Spigot Plugin Development' started by kinukin, Jun 9, 2017.

  1. Code (Text):
                test.put(p.getUniqueId(), "test");
    After putting value in the hashmap, it prints out that the hashmap doesn't contain any value?
  2. Maps are Key and Value, hence Map<UUID, String>

    You are checking to see if it contains the value of a UUID, that is impossible seeing as how your map holds keys of UUID and values of Strings

    The method that would return true would be Map#containsKey.
    • Agree Agree x 2
    • Like Like x 1
  3. Code (Text):
    test.put(p.getUniqueId(), "test");
    If I put this code in a different method. It becomes null if I try to check it in a different method.

    Code (Text):
        public void onInventoryOpen(InventoryOpenEvent e) {
            System.out.println(e.getEventName() + " OPENED!");
            Player p = (Player) e.getPlayer();


                if(test != null) {
                    if(test.containsKey(p.getUniqueId())) {
  4. Firestar311


    I don't see where you put an item into the HashMap in the event code you provided.
    • Agree Agree x 1