Why doesnt this work?

Discussion in 'Spigot Plugin Development' started by Known, Jun 8, 2017.

  1. Code (Text):
    String toTranslate = getConfig().getString("cat");
                String translated = ChatColor.translateAlternateColorCodes('&', toTranslate);
                Bukkit.broadcastMessage(translated);
    This is my stack trace;
    Caused by: java.lang.NullPointerException
    at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.jav
    ~[craftbukkit.jar:git-Bukkit-33d5de3]
    at me.known12.AnimalTalk.Main.onCommand(Main.java:33) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ftbukkit.jar:git-Bukkit-33d5de3]
    ... 14 more
     
  2. ScarabCoder

    ScarabCoder Retired Resource Staff
    Retired

    toTranslate is probably null. It couldn't find the key "cat" in the config.
     
  3. Code (Text):
    String translated = ChatColor.translateAlternateColorCodes('&', toTranslate);
    this is the line that is causing problems, the cat key is in the config btw.
     
  4. Not sure why it is causing the problem.
     
  5. That line of code should function, the reason why that line may be having problems is that there's nothing to translate from the string variable toTranslate. I'd like to see what your config is, I'm willing to bet that it can't find as @ScarabCoder pointed out earlier the key, "cat".
    ~Geekles