Plugin Error Help - javaNullException

Discussion in 'Spigot Plugin Development' started by Shutgorgon1, Jul 18, 2018.

  1. Hello, anyone know how to fix it please?

    [10:17:10] [Server thread/ERROR]: Error occurred while enabling Anni v1.0 (Is it up to date?)
    java.lang.NullPointerException
    at net.Shutgorgon.Annihilation.Translator.change(Translator.java:19) ~[?:?]
    at net.Shutgorgon.Annihilation.Annihilation.onEnable(Annihilation.java:144) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]

    Thanks for all answers! :)
    Good day
     
  2. foncused

    Moderator Patron

    Moved to Spigot Plugin Development.

    If you paste your code, we can help you further - looks like a problem in your Translator class at line 19.
    Code (Text):
    at net.Shutgorgon.Annihilation.Translator.change(Translator.java:19) ~[?:?]
     
  3. Code (Text):
    package net.Shutgorgon.Annihilation;

    import org.bukkit.*;

    public class Translator
    {
        static Annihilation plugin;
       
        public Translator(final Annihilation pl) {
            Translator.plugin = pl;
        }
       
        public static String string(final String id) {
            return ChatColor.stripColor((String)Annihilation.messages.get(id));
        }
       
        public static String change(final String s) {
            String ss = string(s);
            ss = ss.replaceAll("(&([a-fk-or0-9]))", "\u00c2ยง$2");
            return ss;
        }
    }
     
     
  4. What are you trying to get from Messages file? your path seems invalid or the path isnt set maybe
     
  5. In messages.yml i have prefix and some messages. In codes i use (String.valueOf(Translator.change("PREFIX"))
     
    #5 Shutgorgon1, Jul 18, 2018
    Last edited: Jul 18, 2018
  6. Tell me the output using this:
    Code (Text):
    public static String string(final String id) {
            String check = Annihilation.messages.getString(id);
          // If messages is a YamlConfiguration
           if(check==null||check.isEmpty()) {
                 if(Annihilation.messages==null)  {
                        return "x002";
                 } else {
                    if(Annhilation.messages.getKeys(false).length==0) {
                          return "x003";
                    }
                 }
                 return "x001";
           }
            return ChatColor.stripColor((String)Annihilation.messages.get(id));
        }
     
  7. Error occurred while enabling Anni v1.0 (Is it up to date?)
    java.lang.Error: Unresolved compilation problems:
    The method change(String) is undefined for the type Translator
    The method change(String) is undefined for the type Translator

    at net.Shutgorgon.Annihilation.Annihilation.onEnable(Annihilation.java:147) ~[?:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.s(MinecraftServer.java:414) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.k(MinecraftServer.java:378) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:333) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-db6de12-18fbb24]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_181]
     
  8. Package names should be completely lowercase, exception being when pointing to a class prefixed with its package name, like in your imports.
    It looks like the error is being thrown from this line:
    Code (Java):
    ss = ss.replaceAll("&([a-fk-or0-9])", "\u00c2??$2");
    I have no idea what those two characters I replaced with question marks are, but maybe that's the cause? It looks like you're just trying to make a shortcut for ChatColor#translateAlternateColorCodes(), and really you should just use that. I usually use this:
    Code (Java):
    public String addColor(String message) {
        return ChatColor.translateAlternateColorCodes('&', message);
    }
    You should also look into dependency injection and static abuse, because the only variable in that class that isn't static is the class itself.
     
    • Funny Funny x 1
  9. Because the String ss is null (string(String s) its the problem).
     
  10. Use the method string(String) then... like: Prefix = Translator.string("PREFIX");
     
  11. Or he could just use FileConfiguration#isSet(String)
     
  12. If you read above i changed his method xD, to check all possible errors.
     
  13. Sounds long, winded, and ultimately pointless.