Solved Command produces null pointer exception and no output whatsoever.

Discussion in 'Spigot Plugin Development' started by FergyEsHere, Apr 20, 2017.

Thread Status:
Not open for further replies.
  1. Hey.
    I've been working on a plugin, but recently after adding a config to it I got the old null pointer exception (Is it up to date?), which I am familiar with, and I know most ways to fix it. The command was working before then but now it throws that exception and does not work at all.

    plugin.yml: pastebin.com/jdJEhsnh

    Code: pastebin.com/cRur7Pwq

    Command (SafePvPMode): pastebin.com/cncN4J96

    Error: pastebin.com/fmHqKJ97
     
    #1 FergyEsHere, Apr 20, 2017
    Last edited: Apr 20, 2017
  2. The plugin.yml isn't relevant here. We need the command code.
     
    • Agree Agree x 1
  3. Show the stacktrace (the NPE from console) and the code, and point out what line of code the stacktrace is referencing, please.
     
  4. Sorry, was about to do that after I posted, forgot about those things, just edited now.
     
  5. Can you post SafePvPMode class?
     
  6. Yep, did it just before you posted, again, apologies about that.
     
  7. The Error happened at line 22 in your SafePvPMode class, that is this code:

    Code (Text):
    if(!(sender instanceof Player)){
    All i know is that this can't produce a nullpointer, we need the lines from the imports too, or you post the line 22 from your class

    Edit: found your error, you ask for a static load of your "noPermission" , "toggleOn" and "toggleOff"
    from the plugin instance that hasn't been initalized to that time, add your lines to the constructor so that you load the values there and not on a static field

    like this:

    Code (Text):


    String noPermission;
    String toggleOn;
    String toggleOff;

    public SafePvPMode(SafePvP instance){
            plugin = instance;
            noPermission =  ChatColor.translateAlternateColorCodes('&', plugin.getConfig().getString("permissionmessage"));
    ...
       }

     
     
    • Like Like x 1
  8. Thanks for that.
     
Thread Status:
Not open for further replies.