Solved Annoying Error

Discussion in 'Plugin Development' started by chasechocolate, Feb 18, 2013.

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

    chasechocolate

    Hey guys, I have been trying to fix this error that I keep getting. Whenever I try to use this method (I call it in another class) I get this NPE (Nauss is my IGN):
    Code:
    2013-02-18 13:58:24 [INFO] Nauss issued server command: /thehidden setspawn lobby
    2013-02-18 13:58:24 [SEVERE] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'thehidden' in plugin TheHidden v02.17.13
    >      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    >      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186)
    >      at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCommand(CraftServer.java:510)
    >      at net.minecraft.server.v1_4_6.PlayerConnection.handleCommand(PlayerConnection.java:980)
    >      at net.minecraft.server.v1_4_6.PlayerConnection.chat(PlayerConnection.java:898)
    >      at net.minecraft.server.v1_4_6.PlayerConnection.a(PlayerConnection.java:853)
    >      at net.minecraft.server.v1_4_6.Packet3Chat.handle(Packet3Chat.java:44)
    >      at net.minecraft.server.v1_4_6.NetworkManager.b(NetworkManager.java:290)
    >      at net.minecraft.server.v1_4_6.PlayerConnection.d(PlayerConnection.java:112)
    >      at net.minecraft.server.v1_4_6.ServerConnection.b(SourceFile:39)
    >      at net.minecraft.server.v1_4_6.DedicatedServerConnection.b(SourceFile:30)
    >      at net.minecraft.server.v1_4_6.MinecraftServer.r(MinecraftServer.java:598)
    >      at net.minecraft.server.v1_4_6.DedicatedServer.r(DedicatedServer.java:224)
    >      at net.minecraft.server.v1_4_6.MinecraftServer.q(MinecraftServer.java:494)
    >      at net.minecraft.server.v1_4_6.MinecraftServer.run(MinecraftServer.java:427)
    >      at net.minecraft.server.v1_4_6.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    >      at com.chasechocolate.thehidden.cmds.TheHiddenCommand.onCommand(TheHiddenCommand.java:100)
    >      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    >      ... 15 more
    And here is the method that I call on line 100:
    Code:java
    1. public void setLobbySpawn(Player player){
    2. if(plugin.locsFile.exists()){
    3. Location lobby = player.getLocation();
    4. String world = lobby.getWorld().getName();
    5. int x = lobby.getBlockX();
    6. int y = lobby.getBlockY();
    7. int z = lobby.getBlockZ();
    8.  
    9. plugin.locsConfiguration.set("lobby.world", world);
    10. plugin.locsConfiguration.set("lobby.x", x);
    11. plugin.locsConfiguration.set("lobby.y", y);
    12. plugin.locsConfiguration.set("lobby.z", z);
    13. plugin.saveMapsConfig();
    14. }
    15. }

    Thanks for any help!
     
  2. Offline

    tkausl

    Show me Line 100 from TheHiddenCommand.java
     
  3. Offline

    chasechocolate

    tkausl As I said, it is just calling the setLobbySpawn method.
     
  4. Offline

    tkausl

    Then show me, HOW it calls the setLobbySpawn-Method.
    setLobbySpawn isnt the problem. The Problem is, how you call this method.
     
  5. Offline

    chasechocolate

    tkausl
    Code:java
    1. plugin.gameManager.setLobbySpawn(player);

    The gameManager variable in my main class is made with:
    Code:java
    1. GameManager gameManager = new GameManager(this);
     
  6. Offline

    Tirelessly

    plugin is null.
     
  7. Offline

    chasechocolate

    Why would it be null, and how can I make it not-null?
     
  8. Offline

    tkausl

    You have to put your Plugin-Instance to 'plugin'
     
  9. Offline

    chasechocolate

    Tirelessly tkausl Ahh... never mind... I feel stupid. In my main class I never instantiated the variable, it was just:
    Code:java
    1. GameManager gameManager;

    But anyways thanks for your help!
     
  10. Offline

    Tirelessly

    Because I feel like this would still deserve an answer... Only the things that are having called on them will throw a nullpointer. So, in your line of code:

    1. plugin.gameManager.setLobbySpawn(player);
    It won't matter if player is null because nothing is being called on it. setLobbySpawn is a method and can't be null. You posted that you had initialized gameManager. So the only thing that could be null is plugin.
     
Thread Status:
Not open for further replies.

Share This Page