java.lang.NullPointerException错误,请帮忙解决。

huangapple go评论74阅读模式
英文:

java.lang.NullPointerException Errors PLEASE

问题

我对编程非常新手,一直在尝试制作这个 Minecraft 插件。每次我启动它时都会出现这个错误。

这是 "launcher.NitroLauncher.onEnable" 类。

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;
    }
}

任何帮助将不胜感激!

谢谢

英文:

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 &lt;Plugin&gt; void onEnable() {
NitroLauncher.plugin = this;
try {
this.launch = (NitroLaunch)Class.forName(&quot;me.R1J.nitro.NitroPlugin&quot;).asSubclass(NitroLaunch.class).newInstance();
@SuppressWarnings(&quot;unchecked&quot;)
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(&quot;Failed to getValue() with method &quot;
+getFullName()+&quot;: &quot;+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

答案1

得分: 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. java.lang.NullPointerException错误,请帮忙解决。

英文:

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. java.lang.NullPointerException错误,请帮忙解决。

huangapple
  • 本文由 发表于 2020年4月7日 07:20:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/61070445.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定