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?)
        at me.l1ne.login.PLogin.<init>( ~[?:?]
        at me.l1ne.login.IPLogin.onEnable( ~[?:?]
        at ~[craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.loadPlugin( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at org.bukkit.craftbukkit.v1_8_R1.CraftServer.enablePlugins( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.q( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.k( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.MinecraftServer.a( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at net.minecraft.server.v1_8_R1.DedicatedServer.init( [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at [craftbukkit-1.8-R0.1-SNAPSHOT-latest.jar:git-Bukkit-33d5de3]
        at 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