1.14.4 Config returning NPE

Discussion in 'Spigot Plugin Development' started by swendel, Mar 16, 2020.

  1. the config.yml is returning an NPE for certain players when i get their data. I know I'm saving it correctly, and I looked in the config for the player's that have this and it's there. I have no idea what's wrong. Can anyone help? It always happens in one of these. There's no way it's null. Thanks

    Code (Java):
    // Gets the player's class
        public String getRank(Player player) {
            return plugin.getConfig().getString("Players." + player.getUniqueId() + ".Rank");
    // Gets the player's class
        public String getClass(Player player) {
            return plugin.getConfig().getString("Players." + player.getUniqueId() + ".Class");
  2. MrGeneralQ

    MrGeneralQ Previously qintinator

    is your plugin variable defined? Can you post an example of your config? I would also next time keep your properties in your config all lowercase. That will make things easier.
  3. here is an example of someone's data in config
    Code (YAML):

    : Knight
    : true
    : Owner
    : 4
    : 9
    : 0
    : 0
    : 1
    : 0
    : 0
    : 0
    : 2
    : true
    : None
    : None
    : None
    : None
    : 10,7,Creamy
    my plugin variable is defined, i get the main class's instance like this:

    Code (Java):
    private static IvoryRPG instance;
        public IvoryRPG() {
            instance = this;
        public static IvoryRPG getInstance() {
            return instance;
    #3 swendel, Mar 16, 2020
    Last edited: Mar 16, 2020
  4. I assume that's underneath the "Players" key?
  5. yea, sorry i forgot to include that
  6. Something you could try, I dont know if it will exactly fix the issue, but you might try getting the players UUID as a string, so:
    Code (Text):
  7. Does it throw a NPE or does it just return null from the config?
  8. give us the error. show more code.
  9. Also, in this code, instance is indeed null. Do you set it somewhere? In the onEnable or onLoad?
  10. what he means is did you call new IvoryRPG()?
  11. That's not what I mean. Actually you must not create new instances of the class that extends JavaPlugin.
    What I mean is instance = this
  12. throws an NPE
  13. If you combine objects and String objects using the "+"-operator, Object#toString() will be done on every object so that is redundant.
  14. im not sure if youre looking at a different segment of code but his code legit has instance = this in it.. in the constructor of ivoryrpg. and do we know that ivoryrpg is his main class?

    /e i see what youre saying.

    @op, need the stacktrace. we cant help you with an error without seeing the error

    /e op, check if the argumentless constructor is called for javaplugin objects. you're better off declaring the instance in onEnable. but static abuse
  15. stacktrace:
    Code (YAML):
    [ERROR] Could not pass event EntityDeathEvent to IvoryRPG v1.0.0

    : null

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:320) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:529) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:514) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory.callEntityDeathEvent(CraftEventFactory.java:716) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory.callEntityDeathEvent(CraftEventFactory.java:709) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.EntityLiving.d(EntityLiving.java:1369) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.EntityLiving.die(EntityLiving.java:1322) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.entity.CraftLivingEntity.setHealth(CraftLivingEntity.java:114) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at dev.kuzmin04.IvoryRPG.data.Data$2.run(Data.java:232) [IvoryRPG.jar:?]

    at org.bukkit.craftbukkit.v1_14_R1.scheduler.CraftTask.run(CraftTask.java:81) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at org.bukkit.craftbukkit.v1_14_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:394) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.MinecraftServer.b(MinecraftServer.java:1022) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:393) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:815) [spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    at java.lang.Thread.run(Thread.java:813) [?:1.8.0_212]

    Caused by
    : java.lang.NullPointerException

    at dev.kuzmin04.IvoryRPG.data.Data.getRank(Data.java:65) ~[?:?]

    at dev.kuzmin04.IvoryRPG.data.Data.setExperience(Data.java:631) ~[?:?]

    at dev.kuzmin04.IvoryRPG.mobs.MobDrops.drops(MobDrops.java:42) ~[?:?]

    at dev.kuzmin04.IvoryRPG.mobs.MobDrops.death(MobDrops.java:135) ~[?:?]

    at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source) ~[?:?]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_212]

    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_212]

    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[spigot-1.14.4.jar:git-Spigot-cbd1a1b-009d8af]

    ... 16 more
  16. Oh yeah, I didn't even look inside the constructor because it doesn't make sense to create a new instance of the plugin..