Error in start plugin

Discussion in 'Spigot Plugin Development' started by Derperz1215, Oct 9, 2019.

  1. java.lang.NullPointerException
    at Main.Main.configura(Main.java:186) ~[?:?]
    at Main.Main.onEnable(Main.java:96) ~[?:?]
    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(Thread.java:748) [?:1.8.0_222]
     
  2. Something in your "Main.java" class on line 186 is null. Code might help.

    Also naming conventions :(
     
  3. Line 186: if (!getInstance().getConfig().getString("Version").equals(getInstance().getDescription().getVersion())) {
     
  4. try using == operator instead of equals
     
  5. No. You don’t use == for String comparisons.
     
  6. #equals() is perfectly fine for comparing a string. == is used to compare objects.

    Article explaining this: https://www.geeksforgeeks.org/difference-equals-method-java/

    I would assume that your config is null, your instance is null (not sure why you wouldn't just use this inside of your main class but you do you.), or your version string in your config is null.
     
  7. You most likely haven't set the return value for getInstance()
    Wat is your code here?
     
  8. public static List<String> worlds; PluginManager pm;
    public static void configura(Plugin plugin) {
    if (!getInstance().getConfig().getString("Version").equals(getInstance().getDescription().getVersion())) {
    File storageFile1 = null;
    storageFile1 = new File(plugin.getDataFolder(), "config.yml");
    storageFile1.delete();

    getInstance().getLogger().info("this version is Old, Generating new config config.yml to version 1.0");
    plugin.saveResource("config.yml", false);
    getInstance().getLogger().info("Version 1.0 update");
    } else {
    getInstance().getLogger().info("Version 1.0 update");
    }
    }
     
  9. You can't check if a value in the config is set to something when the config is not created (you create it after checking).
    You'd need to check if the "Version" value != null, after that you can check what the Version value is.

    PS: Click "+", "Code", select "Java" and paste your code in there, after that, you can insert it, it's much better to read then ;)
    Code (Java):
    public static List<String> worlds;
    PluginManager pm;
    public static void configura(Plugin plugin) {
        if (!getInstance().getConfig().getString("Version").equals(getInstance().getDescription().getVersion())) {
            File storageFile1 = null;
            storageFile1 = new File(plugin.getDataFolder(), "config.yml");
            storageFile1.delete();

            getInstance().getLogger().info("this version is Old, Generating new config config.yml to version 1.0");
            plugin.saveResource("config.yml", false);
            getInstance().getLogger().info("Version 1.0 update");
        } else {
            getInstance().getLogger().info("Version 1.0 update");
        }
    }
     
    #9 bayerntvplay, Oct 9, 2019
    Last edited: Oct 9, 2019
  10. Show your whole class, getInstance isn't initialized, or your config is empty as said before
     
  11. That is simply wrong. It is used to compare primitives and enums. Here is an example why it does not work for objects.

    Code (Java):
    String first = "hello";
    String second = "hello";

    System.out.println(first == seconds);
    That will print false even though the Strings have the same content
     
  12. You are wrong. This actually return true because in this example "hello" will be reuse from "string constant pool" but when you create new object by usage key word "new" then this objec will be storage in heap like others objects

    Code (Java):
    String text1 = "hello";
    String text2 = "hello";
    String text3 = new String("hello");

    System.out.println(text1 == text2); //true
    System.out.println(text1 == text3); //false
     
  13. Using a constructor for a string that you don't need a copy of is not needed, try to avoid doing that.
     
  14. Sorry, that was a bad example. I did not know about the String Constant Pool. But still, == for primitives and enums, equals for objects.
     
  15. bruh did u even read? he was using it as an example to make a point. he wasnt using it as valid code lol

    more accurately, == compares instance (all primitives have only 1 instance of its reference), #equals compares object content to see if theyre different instances but share the same values. String is sometimes a special case. there are circumstances where you would use == for objects
     
  16. It's my first plugin, and I don't understand much, how would you leave the main then?
     
  17. you're using it in a way thats alright.. but if you want better help, show us the entire class, not just sections.

    if this is true
    then either, getInstance returns null or getString returns null.
    if getInstance returns null, youre not setting it up properly.
    if getString returns null, you're not using configurations correctly.
     
  18. Main.java 186 line is null. Please tell me the code in line 186.
     
    • Funny Funny x 1