Method invocation 'setExecutor' may produce 'NullPointerException'?

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

  1. Offline

    N8TheDev

    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 "MyFirstPlugin.java" and "PluginCommands.java":
    https://paste.gg/p/anonymous/ce3c3bc45a7b4b5e8ad538ee46b69d3b
     
  2. Offline

    SmearySubset

    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

    Shqep

    @N8TheDev
    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.
     

Share This Page