Solved main.instance == null ???

Discussion in 'Plugin Development' started by tuskiomi, Jun 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    tuskiomi

    hello all!
    so i am kindof new to configuration stuff and i was thinking about why i am getting NPEs
    so i added some debugs to my code and what i found is that main.instace (where main is the main class) is a null.
    basically this line:
    Code:java
    1. main.instance.getConfig().getString("Players.p"+Integer.toString(main.playerHashMap.get(EVNT.getPlayer().getDisplayName()))+".team"

    Everything inside the Integer.toString(); returns a 1, I made sure.
    altogether it is "Players.p1.team"
    My config is as follows (dash = space)
    Players:
    --p1:
    ----name: tuskiomi
    ----x: 10
    ---- y: 64
    ---- z: 10
    ----team: red
    I should also mention this is inside a switch/case block where there is a default.
    so what in the code is causing an NPE, and where can i fix it??
     
  2. Offline

    Rocoty

    How can we tell you what part of the code is causing the NPE if we don't have your code?
     
  3. Offline

    tuskiomi

    It's the one line if the first post.....
     
  4. Offline

    Sagacious_Zed Bukkit Docs

    So something in long chain of references is null.... But I guess you already knew that....
     
  5. Offline

    Lolmewn

    tuskiomi Where does it set the main.instance variable? Could you show us that code?
     
  6. Offline

    tuskiomi

    i set the instance like so
    Code:
    public static main instance;
    the naame of the calss is main (like the type).
     
  7. Offline

    Rocoty

    okay, That's the declaration....now show us where you define it
     
  8. Offline

    Lolmewn

    You should define what 'instance' is in your onEnable method. That should fix your issue.
     
  9. Offline

    tuskiomi

    so, what would a user define the instance as?
    I always thought the instance is just to grab methods from the main class.
    edit: grammar

    i went out on a limb and set my instance to
    Code:java
    1. instance = new main();

    and i got this error onJoin:
    Code:java
    1. 11:42:25 AM [SEVERE] Could not pass event PlayerJoinEvent to <myplugin>
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    4. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    5. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    6. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    7. at net.minecraft.server.v1_5_R3.PlayerList.c(PlayerList.java:204)
    8. at net.minecraft.server.v1_5_R3.PlayerList.a(PlayerList.java:100)
    9. at net.minecraft.server.v1_5_R3.PendingConnection.d(PendingConnection.java:129)
    10. at net.minecraft.server.v1_5_R3.PendingConnection.c(PendingConnection.java:44)
    11. at net.minecraft.server.v1_5_R3.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)
    12. at net.minecraft.server.v1_5_R3.DedicatedServerConnection.b(SourceFile:29)
    13. at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:581)
    14. at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:226)
    15. at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:477)
    16. at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:410)
    17. at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    18. Caused by: java.lang.IllegalArgumentException: File cannot be null
    19. at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    20. at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
    21. at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
    22. at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    23. at plugins.tuskiomi.<my plugin>.Evnet.onPlayerJoin(Evnet.java:26)//this is the same line in the first post.
    24. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    25. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    26. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    27. at java.lang.reflect.Method.invoke(Unknown Source)
    28. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    29. ... 14 more


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  10. Offline

    Rocoty

    in onEnable():

    Code:
    instance = this;
     
  11. Offline

    tuskiomi

Thread Status:
Not open for further replies.

Share This Page