getDataFolder in listener class

Discussion in 'Spigot Plugin Development' started by Nolcik, May 24, 2016.

  1. Hello,
    I am trying to getDataFolder in listener class, it causes errors:

    Code (Text):
    Error occurred while enabling IPLogin v1.0 (Is it up to date?)
    java.lang.NullPointerException
        at me.l1ne.login.PLogin.<init>(PLogin.java:36) ~[?:?]
        at me.l1ne.login.IPLogin.onEnable(IPLogin.java:20) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:327) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin(CraftServer.java:341) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins(CraftServer.java:313) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q(MinecraftServer.java:394) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k(MinecraftServer.java:362) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a(MinecraftServer.java:317) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init(DedicatedServer.java:190) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:484) [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at java.lang.Thread.run(Unknown Source)
    There is 20th in IPLogin:
    Code (Text):
    pm.registerEvents(new PLogin(), this);
    and there is 36th in PLogin:
    Code (Text):
    File msg = new File(plg.getDataFolder() + "/messages.yml");
    and plg declaration:
    Code (Text):
    private IPLogin plg;
    Can you help me with that plg.getDataFolder() in PLogin?
    Thank you very much! :)
     
  2. Don't create a new instance of JavaPlugin. When you register events pass an instance of IPLogin to PLogin through the constructor. If you don't know what a constructor or instance is you should probably learn a bit more Java or at least look at the tutorials and learn that in about an hour.

    Also, if you need more help or what I said didn't work, post your code. It's pretty hard to solve the problem with 4 lines of code and an error message.
     
  3. You need to instantiate the instance of PLogin with new PLogin()
     
    • Optimistic Optimistic x 2
    • Agree Agree x 1