Convert getKey to UUID

Discussion in 'Plugin Development' started by Mathie, Feb 10, 2016.

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

    Mathie

    Hello,

    I want convert getKey() to UUID:

    Code:
            for (Map.Entry mapentry : map.entrySet()) {
                uuid = (UUID) mapentry.getKey();
            }
    
    I have another function that checks if the ID is not found in another map:

    Code:
        boolean checkUUID(UUID uuid){
            for (Map.Entry mapentry : map2.entrySet()) {
                if (mapentry.getKey().equals(uuid)) {
                    return false;
                }
            }
            return true;
        }
    I call this function in a condition:

    Code:
    if (checkUUID(uuid)) {
          System.out.println("uuid");
    }
    I have a NullPointerException in the console ..

    Thanks !
     
    Last edited: Feb 11, 2016
  2. Offline

    WolfMage1

    @Mathie
    Code:
    HashMap<UUID,/*whatever else you're storing*/> myHashMap = new HashMap<>();
    for(Map.Entry</*whats in the angle brackets of your map*/> myEntrySet : myHashMap.entrySet()) {
        if(myEntrySet.getKey().equals(/*the uuid*/) {
            //What you want to do.
        }
    }
    
    1
     
  3. Offline

    Zombie_Striker

    @Mathie
    What line is causing the NPE?
     
  4. Offline

    Mathie

     
  5. Offline

    teej107

    @Mathie That line wouldn't cause an NPE. Could you show us what's inside that method?
     
  6. Offline

    Mathie

    I was wrong ... sorry

    My function:

    Code:
        boolean checkUUID(UUID uuid){
            for (Map.Entry mapentry : map2.entrySet()) {
                if (mapentry.getKey().equals(uuid)) {
                    return false;
                }
            }
            return true;
        }
     
  7. Offline

    Zombie_Striker

    @Mathie
    Are you sure that is the line? The only thing that could be null would be the uuid.
     
  8. Offline

    Mathie

    If I put in the comments if I have any errors.
    If I remove the comment, I get an error ..
     
  9. Offline

    teej107

    @Mathie Show us the exact line that the NPE is happening on.
     
  10. Offline

    Mathie

    Problem solved.
    I tried to browse a map null
     
Thread Status:
Not open for further replies.

Share This Page