读取yml文件时出现问题

时间:2019-05-27 05:38:49

标签: java yaml

我在读取yml文件时遇到问题 这是代码:

private void jbtaskUsuarioActionPerformed(ActionEvent evt) {
  click.play();
  try {
    File file = new File("/net/luisalvacelis/sv/archives/config.yml");
    YamlConfiguration fileyaml = YamlConfiguration.loadConfiguration(file);
    if (fileyaml.getString("Categoria").contains("Selecc")) {
      JOptionPane.showMessageDialog(null, "Error: No hay elecciones programadas.", "Error", 0, new ImageIcon(getClass().getResource("/net/luisalvacelis/sv/image/error24x24.png")));
    } else {
      dispose();
    }
  } catch (Exception e) {
    JOptionPane.showMessageDialog(null, e);
  }
}

这是yml包含的内容:

Categoria: "-- Selecc --"

MySQL:
  enabled: false
  host: localHost
  port: 3306
  dataBase: dataBase
  userName: name
  password: 123

Twitter:
  oAuthConsumerKey: "oAuthConsumerKey"
  oAuthConsumerSecret: "oAuthConsumerSecret"
  oAuthAccessToken: "oAuthAccessToken"
  oAuthAccessTokenSecret: "oAuthAccessTokenSecret"

YamlConfiguration方法来自该库:

org.bukkit.configuration.file.YamlConfiguration;

这是错误:

java.lang.NullPointerException
at net.luisalvacelis.sv.jframes.Principal.jbtaskUsuarioActionPerformed(Principal.java: 182)
at net.luisalvacelis.sv.jframes.Principal.access$1(Principal.java: 177)
at net.luisalvacelis.sv.jframes.Principal$3.actionPerformed(Principal.java: 89)

如果文件路径正确且数据正确,为什么我会得到null?

更好的错误图片: https://imgur.com/U77JGhR

基本上我使用相同的代码 https://imgur.com/AY2yac1 https://imgur.com/cd3hvCh

0 个答案:

没有答案