0

私は Java 6 で作業しており、次の問題が発生しました。

null である必要がある 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

It's not regions that's null. It's probably either plugin or the result of getLogger().

于 2013-06-28T18:56:13.367 に答える