getConfig() returns null with path and values there?

Discussion in 'Plugin Development' started by adam561, Aug 12, 2014.

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

    adam561

    I have the x,y,z, yaw, and pitch values of a location stored in my config, They are there when I look at the config but accessing them from my code gives me a NPE.

    CODE:
    Code:
    String path = "game.worlds." + w.getName() + ".tdm." + w.getName()+".blue";
            int x = pl.getConfig().getInt(path + ".x"); // WHAT NPE POINTS TO
            int y = pl.getConfig().getInt(path+".y");
            int z = pl.getConfig().getInt(path+".z");
            int pt = pl.getConfig().getInt(path+".pt");
            int ya = pl.getConfig().getInt(path+".ya");
            return new Location(w,x,y,z,ya,pt);
    and my config: ( "t" is the name of the world)
    Code:
    game:
      worlds:
        t:
          tdm:
            red:
              x: 0
              y: 1
              z: 0
              ya: 0.0
              pt: 0.0
            blue:
              x: -1
              y: 1
              z: 0
              ya: 4.05
              pt: 4.3500004
    I know that the "w" value in the code isnt null. What am I missing? I use this same method many other times in my code and dont get any errors...
     
  2. Offline

    Skionz

    Are you checking if the value is null before checking for a value?
    Code:
    if(getConfig().contains(path)) {
        //get the values
    }
     
  3. Offline

    adam561

    Yep!
    that returns true and still gives me the same NPE,
     
  4. Offline

    Totom3

    You are searching for "games.worlds.t.tdm.t.blue" which is not preset in your config (second "t" is missing).
     
  5. Offline

    adam561

    WOW, thanks.... i feel soo stupid....
     
    Totom3 likes this.
  6. Offline

    Totom3

    I used to do this all the time xD
     
Thread Status:
Not open for further replies.

Share This Page