0

Im really new to coding and ive been trying to make this minecraft plugin. Every time I launch it I get this error. https://i.imgur.com/33lBHQr.png

Here is the "launcher.NitroLauncher.onEnable" class.

package launcher;

import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.plugin.java.JavaPlugin;

public class NitroLauncher extends JavaPlugin
{
    private NitroLaunch launch;
    private static NitroLauncher plugin;
    private ReflectiveOperationException e;

    public <Plugin> void onEnable() {
        NitroLauncher.plugin = this;
        try {
            this.launch = (NitroLaunch)Class.forName("me.R1J.nitro.NitroPlugin").asSubclass(NitroLaunch.class).newInstance();
            @SuppressWarnings("unchecked")
            Plugin plugin2 = (Plugin)this;
            new BukkitRunnable() {
                public void run() {
                    NitroLauncher.this.launch.launch(NitroLauncher.this);
                }
            }.runTask((org.bukkit.plugin.Plugin) plugin2);
        }
        catch (InstantiationException | IllegalAccessException | ClassNotFoundException ex2) {
            String str = e.getMessage(); ;
            ;
            e = new ReflectiveOperationException(str);;
            e.printStackTrace();
        }
    }

    public Object getValue(Object pojo) throws IllegalArgumentException
    {
      try {
        return _method.invoke(pojo, (Object[]) null);
      } catch (IllegalAccessException | InvocationTargetException e) {
        throw new IllegalArgumentException("Failed to getValue() with method "
            +getFullName()+": "+e.getMessage(), e);
      }
    }

    public void onDisable() {
        if (this.launch != null) {
            this.launch.shutdown();
        }
        this.launch = null;
        NitroLauncher.plugin = null;
    }

    public static NitroLauncher getPlugin() {
        return NitroLauncher.plugin;
    }
}

Any help would be greatly appreciated!

Thanks

Nicolas
  • 8,077
  • 4
  • 21
  • 51
  • the error is showing in line 26 but that's just the message inside the `catch` clause, which means the actual error is happening inside the `try`between lines 15 and 24. Check to see if any of the elements you're using there returns null, at a glance the main suspect might be `Class.forName("me.R1J.nitro.NitroPlugin")` – Scaramouche Apr 06 '20 at 23:28
  • You have a bunch of non-needed semi-colons around the line 26. Try to remove them and check what happen. – Nicolas Apr 06 '20 at 23:37

1 Answers1

1

line 11:

private ReflectiveOperationException e;

you're trying to call getMessage() on it before initializing it. on lines 26-28:

String str = e.getMessage(); ;
        ;
        e = new ReflectiveOperationException(str);;

Since the variable 'e' isn't set to anything yet, it defaults to a value of 'null'.

when you try to do something like call a function on with a variable that is null, it results in that NullPointerException.

Always double check your code for silly mistakes like this, because 99% of the time that's what ends up breaking your program. :)

  • 2
    You could add that at this point ( `e.getMessage()` ) , they are looking for the error variable, which is defined as `ex2` – Nicolas Apr 07 '20 at 12:05