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);
    This is my stack trace;
    Caused by: java.lang.NullPointerException
    at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.jav
    at me.known12.AnimalTalk.Main.onCommand(Main.java:33) ~[?:?]
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 14 more
  2. ScarabCoder

    ScarabCoder Retired Resource Staff

    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".