英文:
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 <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
答案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.
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论