can someone help me with an NPE? (config)

Discussion in 'Plugin Development' started by tuskiomi, Jun 22, 2013.

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

    tuskiomi

    hello all!
    I get an NPE whenever my plugin gets to this line of code:
    Code:
                switch(main.instance.getConfig().getString("Players.p"+main.playerHashMap.get(EVNT.getPlayer().getDisplayName())+".team")){
    where EVNT is a playerjoin event
    and main is the main class
    and playerhashmap is a string-key and int value hashmap

    my config is as follows:

    Players:
    --p1:
    ---- name: tuskiomi
    ----x: 10
    ----y: 64
    ----z: 10
    ----team: red
     
  2. Offline

    Ivan

    main, instance or the string you get is returning null. add null checks
     
  3. Offline

    tuskiomi

    okay i added some debuggers in my code.
    Code:java
    1. if(main.instance == null){
    2. main.log.info("main instance is null");//idk, but just in case
    3. }
    4. if(EVNT.getPlayer().getDisplayName() == null){
    5. main.log.info("display name is null");// if the user is herobrine, this will pop up
    6. }
    7. if(main.playerHashMap.get(EVNT.getPlayer().getDisplayName()) == 0){
    8. main.log.info("add 1");//if the hashmap returns 0 tell me to add 1
    9. }


    this was the result
    why is my main instance a null and how do i fix it?

    poke

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
Thread Status:
Not open for further replies.

Share This Page