0

我在 Java 6 下工作并遇到以下问题:

我有一个应该为空的 ArrayList。if 应该捕获它,但 if 没有捕获它,我在它下面的行中得到一个 nullPointerException。

31    public static Region resolve(Location location, World world) {
32        //Get all Regions in this World
33        ArrayList<ProtectedRegion> regions = ListStorage.get(world);
34
35        //If no regions in this world, a player cant be in one
36        if (regions == null) {
37            plugin.getLogger().info("Regions is null");
38           return null;
39        }
40
41        plugin.getLogger().info(""+regions.size());
42
43        //Check every region if the player is in it
44        for (ProtectedRegion region : regions) {
45            if(region.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ())) {
46                String shopName = WorldGuardBridge.convertRegionToShopName(region, world);
47                if(shopName == null) {
48                    shopName = region.getId();
49                }
50
51                plugin.getLogger().info(region.toString());
52
53                return resolve(shopName, world);
54            }
55        }
56
57        //The player is in no shop
58        return null;
59    }

ListStorage 是一个基本的 ConcurrentHashMap>。我得到的错误:

20:40:37 [SEVERE] Could not pass event PlayerJoinEvent to RegionShop v1.1.0b4
org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:26)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:479)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:464)
        at net.minecraft.server.v1_5_R3.PlayerList.c(PlayerList.java:204)
        at net.minecraft.server.v1_5_R3.PlayerList.a(PlayerList.java:100)
        at net.minecraft.server.v1_5_R3.PendingConnection.d(PendingConnection.java:134)
        at net.minecraft.server.v1_5_R3.PendingConnection.c(PendingConnection.java:49)
        at org.spigotmc.MultiplexingServerConnection.b(MultiplexingServerConnection.java:77)
        at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:583)
        at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:227)
        at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:472)
        at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:404)
        at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
Caused by: java.lang.NullPointerException
        at com.geNAZt.RegionShop.Region.Resolver.resolve(Resolver.java:41)
        at com.geNAZt.RegionShop.Listener.PlayerJoin.onPlayerJoin(PlayerJoin.java:28)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 14 more
4

1 回答 1

4

不是regions那样的null。这可能是 要么 要么plugin的结果getLogger()

于 2013-06-28T18:56:13.367 回答