NullPonter Error

Discussion in 'Plugin Development' started by dgramop, Feb 1, 2016.

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

    dgramop

    Hello!
    [EDIT] Reader friendly
    I need help solving this error:

    Code:
    [20:45:54 WARN]: java.lang.NullPointerException
    
    [20:45:54 WARN]: at com.gramollc.dhruv.PvPPlugin.onPlayerJoin(PvPPlugin.java:178)
    
    [20:45:54 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    
    [20:45:54 WARN]: at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    
    [20:45:54 WARN]: at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    
    [20:45:54 WARN]: at java.lang.reflect.Method.invoke(Method.java:497)
    
    [20:45:54 WARN]: at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300)
    
    [20:45:54 WARN]: at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    
    [20:45:54 WARN]: at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501)
    
    [20:45:54 WARN]: at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:282)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:748)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632)
    
    [20:45:54 WARN]: at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540)
    
    [20:45:54 WARN]: at java.lang.Thread.run(Thread.java:745)
    
    [20:45:54 ERROR]: Could not pass event PlayerJoinEvent to dGRAMOPPvPPlugin v1.0
    
    org.bukkit.event.EventException
    
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-e8c6403]
    
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-e8c6403]
    
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:282) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:748) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [craftbukkit.jar:git-Bukkit-e8c6403]
    
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_66]
    
    Caused by: java.lang.NullPointerException
    
    at com.gramollc.dhruv.PvPPlugin.onPlayerJoin(PvPPlugin.java:182) ~[?:?]
    
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_66]
    
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_66]
    
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_66]
    
    at java.lang.reflect.Method.invoke(Method.java:497) ~[?:1.8.0_66]
    
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-e8c6403]
    
    ... 14 more
    

    My on enable function:
    Code:
    @EventHandler
    
    public void onPlayerJoin(PlayerJoinEvent e)
    
    {
    
    this.logger.info("start");
    
    if(!e.getPlayer().hasPlayedBefore())
    
    {
    
    dataFile.set("users."+e.getPlayer().getName()+".points", "10");
    
    try {
    
      dataFile.save(f);
    
    } catch(IOException err) {
    
      err.printStackTrace();
    
    }
    
    }
    
    int n=1;
    
    while(n<=this.getConfig().getInt("numberOfRanks"))
    
    {
    
    if(dataFile.getConfigurationSection("users."+e.getPlayer().getName()).getInt("points")>=this.getConfig().getConfigurationSection("ranks."+n).getInt("PvPPoints"))
    
        {
    
        dataFile.set("users."+e.getPlayer().getName()+".rank", this.getConfig().getConfigurationSection("ranks."+n).getString("rankName"));
    
        }
    
    }
    
    try{
    
    [[[LINE 178>>>]]]e.getPlayer().setDisplayName("["+this.getConfig().getConfigurationSection("ranks."+dataFile.getConfigurationSection("users."+e.getPlayer().getName()).getString("rank")).getString("rankName") +"] "+e.getPlayer().getName());//line 178
    
    } catch(Exception err)
    
    {
    
    err.printStackTrace();
    
    this.logger.info(this.getConfig().getConfigurationSection("ranks.1").getString("rankName"));
    
    }
    
    }
     
    Last edited: Feb 9, 2016
  2. Offline

    pie_flavor

  3. Offline

    dgramop

  4. Offline

    dgramop

  5. Offline

    pie_flavor

    @dgramop the reason i suggested [code] blocks was because the indentation was removed, and everything had a linebreak.
    you didn't really change that.
    try recopying it from the file.
     
  6. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
    @dgramop Could you post your code as well?
     
  7. Offline

    dgramop

  8. Offline

    teej107

    @dgramop Please show us the line that the NPE is occurring on.
     
  9. Offline

    dgramop

    @teej107 I put a comment on that line. This line 46

    Any more problems with how my code looks, please use a java beutifier yourself


    [merged by moderator]
     
    Last edited by a moderator: Feb 7, 2016
  10. Offline

    mcdorli

    This code is not readable, the problem is on line 182, but because it is so fu***d up, I don't know where that line is. If you don't want to do anything abput that, thenn I'm sorry, but no one is going to help you.

    Do you own the gramollc.com domain?
     
  11. The problem is not your onEnable code. It's the onPlayerJoin method. Please post it, too.
     
  12. Offline

    teej107

  13. Offline

    dgramop

    @mcdorli I do not own the gramollc.com domain, but I am afilliated with it's owner. I maintain that site.
    This http://dgramop.co is my site. I am a big web developer, I am new(ish) to bukkit plugin dev, while

    @teej107 I'm not THAT stupid (fair for you to think so, I phrased incorrectly, no guilt trip), understand that something up on that line is giving a null value when we need an object. The question I am asking is how it is getting there? I initialized all my vars etc. Something in either config.yml or data.yml is f'd up.

    Thank you all for participating in this thread! Your continued help is very much appreciated

    @mcdorli By the way, how did you link me to that domain? You are a talented [google] searcher! I just want to try and take things off the web that may link me to other people etc.
     
  14. Offline

    timtower Administrator Administrator Moderator

    @dgramop The configs are probably indeed the issue.
    Split the lines, find the null value.
     
  15. Offline

    mcdorli

    1.: Use reply or quotes instead of tahgs, they work better
    2.: I have ny techniques.
    1. [20:45:54 WARN]: at com.gramollc.dhruv.PvPPlugin.onPlayerJoin(
    You know, the basic mind-reading-trough-internet.

    If the domains owner gave you permission, to use the domain, then I don't have any problems with that at all.
     
  16. Offline

    dgramop

    "Split the lines" -> What do you mean? you mean add a nextline like

    item:
    item:
    item:

    to

    item:

    item:

    item:

     
  17. Offline

    pie_flavor

    it's a personal preference whether to use quotes or not. I only use quotes when I am referring to a specific thing they are saying, such as in this post. They do not in fact 'work better', they send a notification, same as tagging, and in fact if I am subscribed to a thread (i.e. receiving notifications about every post), replies/quotes send me extra notifications whereas tags do not.
     
  18. Offline

    mcdorli

    Tahgs don't work likebhalf of the time
    Quotes do.

    Java doesn't care about line ends, it only ends a line, if he finds a semicolon, so technically, you can do

    pligin.
    getConfig().
    getString(“hello“);

    If you put a new line after every dot, the error will show exactly, what is null and what isn't
     
  19. Offline

    dgramop

    @mcdorli

    Again, I already know that java ends at the semi colon, I have lots of java (and even more C Style language and python experience. Maybe you are right, I should put nextlines so that the error will tell me where in that pile of sh~t it is.

    If anyone has found a different answer, please reply to this thread, other users may have similar questions, or this answer may not work
     
  20. Offline

    Xerox262

    @dgramop If you don't want to spit it up then the possible things that would be null could be.

    The file dataFile.
    The config might not contain the section "ranks." + player's name.
    The config might not contain the section "users." + player's name.
    The config might not contain the string "rank"
    The config might not contain the string "rankName"

    Print them out and see what is null.
     
  21. Offline

    dgramop

    @Xerox262 You mean

    users.+player's name

    and

    ranks+(users.+player's name)

    I will try that too

    Keep dem posts comming!
     
Thread Status:
Not open for further replies.

Share This Page