Method invocation 'setExecutor' may produce 'NullPointerException'?

Discussion in 'Plugin Development' started by N8TheDev, Jul 30, 2021.

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


    I know that this is a common problem and I have seen many solutions but none of them are fixing my issue. I am attempting to make my first plugin with a /heal command and followed 2 different tutorials with very similar steps. To add the command to the onEnable() function you use the following code,

    " getCommand("heal").setExecutor(new PluginCommands(this)); "

    But when I put that in the code I get the error shown in the title I've looked at many threads and even looked at the hint in IntelliJ and nothing is working. If someone could help me out it would be very much appreciated :)

    BTW here is the "" and "":
  2. Offline


    Ok I originally typed up a response but then I realized everything I said you already did but now I don't know how to delete a reply so here I am typing out a random response. Sorrry
    Last edited: Aug 7, 2021
  3. Offline


    It's not an error, it's a warning. Your code would compile fine. The IDE says that because the getCommand(name) method returns a Nullable value.
    It returns null when you didn't register the command in your plugin.yml. The IDE is just warning you that invoking a method on a null can produce a NullPointerException. That's all.
Thread Status:
Not open for further replies.

Share This Page