-2
try {
    float newRep = Float.parseFloat(split[1]);
    String target = split[0];
    for (File file : getDataFolder().listFiles()) {
        if (file.getName().equalsIgnoreCase(target + ".yml")) {
            File targetFile = file;
            try {
                FileConfiguration config = YamlConfiguration.loadConfiguration(targetFile);
                config.set("data.rep", newRep);
                config.save(targetFile);
                sender.sendMessage(ChatColor.GREEN + target + ChatColor.RED
                        + "'s rep is now set to " + ChatColor.GREEN + newRep);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
} catch (NumberFormatException ex) {
    sender.sendMessage(ChatColor.RED + "Must be a number!");
} catch (IllegalArgumentException e) {
    sender.sendMessage(ChatColor.RED + "Player not found!");
} catch (NullPointerException e) {
    sender.sendMessage("Unknown pointer error!");
    e.printStackTrace();
}

基本上有些东西会引发空点错误。真是被蒙蔽了。所有代码都在尝试打开基于split[0]数组的 yaml 文件。然后将 yaml 中的值之一更改为字符串split[1](传递给浮点数)。

这是堆栈跟踪:

23:25:18 [SEVERE] java.lang.NullPointerException
23:25:18 [SEVERE]   at com.github.scullyking.reputation.Command_Set.onCommand(Command_Set.java:33)
23:25:18 [SEVERE]   at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
23:25:18 [SEVERE]   at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:191)
23:25:18 [SEVERE]   at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
23:25:18 [SEVERE]   at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchServerCommand(CraftServer.java:512)
23:25:18 [SEVERE]   at net.minecraft.server.v1_6_R2.DedicatedServer.ar(DedicatedServer.java:262)
23:25:18 [SEVERE]   at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:227)
23:25:18 [SEVERE]   at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
23:25:18 [SEVERE]   at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
23:25:18 [SEVERE]   at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)'

好的,所以第 33 行是 for 循环。

4

1 回答 1

0

该方法getDataFolder()正在返回null

然后你调用.listFiles()返回的东西,然后繁荣。

于 2013-08-04T22:41:57.323 回答