无法在数组或列表中使用对象
我创建了一个简单地扩展 java.lang.Object 的类。
我可以单独使用这个对象来创建它的任意数量的实例,但我似乎无法在数组或列表中使用它。
public static Area[] areas = null;
areas[0] = new Area(340, 64, -189, 20, wl);
// Note that <Area> was something my compiler warned me to do, after I tried without it
public static List<Area> areaList;
areaList.add(0, new Area(340, 64, -189, 20, wl));
它总是会出现 NullPointerException
:
07:58:11 [SEVERE] Error occurred while enabling EasyProtect v1.0 (Is it up to date?): null
java.lang.NullPointerException
at main.EasyProtect.onEnable(EasyProtect.java:41)
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:920)
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:278)
at net.madjawa.pluginreloader.PluginReloader.loadPlugin(PluginReloader.java:232)
at net.madjawa.pluginreloader.PluginReloader.onCommand(PluginReloader.java:85)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:39)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:353)
at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:756)
at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:721)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:714)
at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:92)
at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:464)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
I have created a class that simply extends java.lang.Object
.
I can use this object on its own to create any number of instances of it, but I cannot seem to use it inside an array or list.
public static Area[] areas = null;
areas[0] = new Area(340, 64, -189, 20, wl);
// Note that <Area> was something my compiler warned me to do, after I tried without it
public static List<Area> areaList;
areaList.add(0, new Area(340, 64, -189, 20, wl));
It always comes up with a NullPointerException
:
07:58:11 [SEVERE] Error occurred while enabling EasyProtect v1.0 (Is it up to date?): null
java.lang.NullPointerException
at main.EasyProtect.onEnable(EasyProtect.java:41)
at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:126)
at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:920)
at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:278)
at net.madjawa.pluginreloader.PluginReloader.loadPlugin(PluginReloader.java:232)
at net.madjawa.pluginreloader.PluginReloader.onCommand(PluginReloader.java:85)
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:39)
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:163)
at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:353)
at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:756)
at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:721)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:714)
at net.minecraft.server.Packet3Chat.a(Packet3Chat.java:33)
at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:92)
at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:464)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是因为它们是
null
。使用:
This is because they are
null
.Use:
你实例化了你的列表吗?
Did you instantiated your list?
在使用数组之前,您需要实例化该数组。
否则,当您尝试使用该数组时,您将收到
NullPointerException
。对于任何对象都是如此,包括
List
。You need to instantiate the array before you use it.
Otherwise, when you try to use the array, you'll get a
NullPointerException
.The same is true for any object, including
List
.