Solved Cannot figure out this NPE D:

Discussion in 'Plugin Development' started by Fiddy_percent, Jul 26, 2014.

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

    Fiddy_percent

    So I have a general playerclass FcPlayers and in that class I have a getter and setter job method inside like so
    Code:java
    1. private String playerJob;


    Code:java
    1. public FcPlayers(FiddyCraft plugin, Player P){
    2. this.plugin = plugin;
    3. Player p = P;
    4. allPlayers = plugin.getPlayerInfo().getConfigurationSection("Players").getKeys(false);
    5. Name = p.getName();
    6. playerJob = plugin.getPlayerInfo().getString("Players." +p.getUniqueId().toString()+ ".Job");
    7. }


    Code:java
    1. public String getPlayerJob(){
    2. return playerJob;
    3. }


    Code:java
    1. public void setPlayerJob(String pJob){
    2. plugin.getPlayerInfo().set("Players." +p.getUniqueId().toString() + ".Job", pJob);
    3. plugin.savePlayerInfo();
    4. }


    and the method I have for initially setting all this

    Code:java
    1. public void setNewPlayer(Player p ){
    2. if(!this.getPlayerInfo().contains("Players.")){
    3. this.getPlayerInfo().set("Players", "Yo mama");
    4. this.savePlayerInfo();
    5. }
    6. this.getPlayerInfo().set("Players." +p.getUniqueId().toString() + ".Job", "Unemployed");
    7. this.savePlayerInfo();
    8. }


    and my playerfile looks like this

    Code:
    Players:
      e3e271ef-9134-30c9-b624-181e8a3e5810:
        Name: Fiddy_percent
        StartDate: 2014/07/26 11:12
        Job: Unemployed
        Arrests: 0
        Convictions: 0
        Murders: 0
        Wanted: false
        On Parol: false
        Pending Trial: false
        Can Lawyer: false
        Max Food Level: 2
        Max Crops: 16
        Max Animals: 4
    yet it always comes back saying that
    Code:
    by: java.lang.NullPointerException
        at io.github.FiddyPercent.fiddycraft.FcPlayers.setPlayerJob(FcPlayers.java:150) ~[?:?]
    line 150 being
    Code:
            plugin.getPlayerInfo().set("Players." +p.getUniqueId().toString() + ".Job", pJob);
     
  2. Offline

    Dragonphase

    Fiddy_percent

    Would you be able to provide the entirety of your FcPlayers.java class using pastie? It'll just save us the trouble of blindly throwing invalid answers at you.
     
  3. Offline

    tempelis

    You are getting a NullPonterException, this means you are trying to use something that is null in an instance where it needs an object. From the code I see pJob is initialized but has no value to it. So it's returning that value null while it doesn't want a null value. Did you mean to put playerJob there?
     
  4. Offline

    Fiddy_percent

    this is the what I use to set the player job

    Code:java
    1. FcPlayers fcp = new FcPlayers(plugin,p);
    2. fcp.setPlayerJob("Farmer");


    it shouldn't be null.

    yeah sure. This is also happening for another class I created and I have no clue why I keep getting nulls

    http://pastebin.com/DibGJzWv

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    Dragonphase

    Fiddy_percent

    Well there's your error. You're not initializing your private Player p. On line 35, remove the "Player" so it reads "p = P".
     
    Fiddy_percent likes this.
  6. Offline

    Fiddy_percent

    Dragonphase likes this.
  7. Offline

    Dragonphase

Thread Status:
Not open for further replies.

Share This Page