必须提供节点

时间:2018-02-08 12:25:48

标签: java

我无法保存我的YAML文件。我有一个NPE而没有任何东西。

我多次使用此备份方法,从未遇到过此错误。我尝试过调试,但没有任何作用。

public void sendMail(List<SendMail> mails, boolean notify)
{
    for(SendMail mail : mails)
    {
        int id = getMailIndex(mail.getUuid()) + 1;
        Map<Integer, Mail> m = getAllMailFor(UUID.fromString(mail.getUuid()));
        if(mail != null) {
            m.put(id, new Mail(id, mail.item, mail.getExp()));
            this.mails.remove(UUID.fromString(mail.getUuid()));
            this.mails.put(UUID.fromString(mail.getUuid()), m);
        }
        String path = mail.getUuid() + "." + id;
        config.getMailYAML().set(path + ".item", mail.getItem());
        config.getMailYAML().set(path + ".time", Long.valueOf(System.currentTimeMillis() / 1000L));
        config.getMailYAML().set(path+".exp", mail.getItem());
        if(path == null) System.out.println("PATH");
        if(config.getMailYAML().get(path+".item") == null) System.out.println("ITEM");
        if(config.getMailYAML().get(path+".time") == null) System.out.println("TIME");
        if(config.getMailYAML().get(path+".exp") == null) System.out.println("EXP");
        incrementMailIndex(mail.getUuid());
        if (notify) {
            Player reciever = this.instance.getServer().getPlayer(UUID.fromString(mail.getUuid()));
            if (reciever != null){
                reciever.sendMessage(this.instance.getHDVPrefix() + "§7Vous avez reçu un mail §e/hdv mail");
                reciever.playSound(reciever.getLocation(), Sound.BLOCK_NOTE_PLING, 10, 10);
            }
        }
        Bukkit.getScheduler().runTaskAsynchronously(HDV.getInstance(), new Runnable() {
            @Override
            public void run() {
                config.saveMail();
            }
        });
    }
}

错误:

java.lang.NullPointerException: Nodes must be provided.
    at org.yaml.snakeyaml.nodes.NodeTuple.<init>(NodeTuple.java:28) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:163) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:306) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.bukkit.configuration.file.YamlRepresenter$RepresentConfigurationSection.representData(YamlRepresenter.java:23) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:94) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representMapping(BaseRepresenter.java:156) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.SafeRepresenter$RepresentMap.representData(SafeRepresenter.java:306) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.java:94) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:64) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:242) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.Yaml.dumpAll(Yaml.java:206) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.yaml.snakeyaml.Yaml.dump(Yaml.java:181) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.bukkit.configuration.file.YamlConfiguration.saveToString(YamlConfiguration.java:39) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.bukkit.configuration.file.FileConfiguration.save(FileConfiguration.java:68) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at com.elenox.hdv.manager.ConfigManager.saveMail(ConfigManager.java:85) ~[?:?]
    at com.elenox.hdv.manager.HDVManager$5.run(HDVManager.java:207) ~[?:?]
    at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftTask.run(CraftTask.java:71) ~[Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at org.bukkit.craftbukkit.v1_11_R1.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:52) [Spigot.jar:git-Spigot-3fb9445-6e3cec8]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_161]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_161]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_161]

线HDVManager:207

config.saveMail();

1 个答案:

答案 0 :(得分:0)

抛出NPE的方法的源代码是:

public NodeTuple(Node keyNode, Node valueNode) {
    if (keyNode == null || valueNode == null) {
        throw new NullPointerException("Nodes must be provided.");
    }
    this.keyNode = keyNode;
    this.valueNode = valueNode;
}

正如您所看到的,构造函数表示已使用无效(null)参数调用它。

进一步查看堆栈跟踪,并进行更多挖掘,看起来有些东西正在调用带有错误的Bukkit Configuration对象的YAML序列化程序;例如它有null而不是键或值。

您应该能够使用调试器确定它是null的键还是值。

  

我有一个NPE而没有任何东西。

显然不是这样。从上面的代码中可以看出,由于存在null,因此抛出该消息的异常。

更正确的说法是您没有找到导致问题的null。然而。继续寻找。