Configuration problem

Discussion in 'Plugin Development' started by civ77, Jan 10, 2012.

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

    civ77

    I am getting this error when I try to enable my plugin (I did not get it before adding the configuration):
    Show Spoiler

    Code:
    2012-01-10 16:43:14 [SEVERE] Error occurred while enabling ExpBank v0.3 (Is it up to date?): null
    java.lang.NullPointerException
    	at me.hayden.expbank.ExpBank.onEnable(ExpBank.java:78)
    	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:228)
    	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:970)
    	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
    	at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
    	at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:348)
    	at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:335)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:165)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:399)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)

    Here is the configuration related stuff from my main class (made with this tutorial):
    Show Spoiler

    Code:
    	FileConfiguration ExpBankConfig;
    	public double config_bankxcoord = 0;
    	public double config_bankycoord = 64;
    	public double config_bankzcoord = 0;
    	public String config_bankworld = "world";
    
            @Override
    	public void onEnable(){
    	    ExpBankConfig.options().header("Set your Bank Location");
    	    ExpBankConfig.addDefault("Bank Location.X", 0);
    	    ExpBankConfig.addDefault("Bank Location.Y", 64);
    	    ExpBankConfig.addDefault("Bank Location.Z", 0);
    	    ExpBankConfig.options().copyDefaults(true);
    	    saveConfig();
    	    config_bankxcoord = (Double) ExpBankConfig.get("Bank Location.X");
    	    config_bankycoord = (Double) ExpBankConfig.get("Bank Location.Y");
    	    config_bankzcoord = (Double) ExpBankConfig.get("Bank Location.Z");
    	}
    
     
  2. Offline

    wwsean08

    what line is line 78?
     
  3. Offline

    theguynextdoor

    What specifically is line 78?

    Add this to your onEnable
    Code:java
    1. FileConfiguration ExpBankConfig = this.getConfig();


    Because i do believe you never actually set what ExpBankConfig was referring to

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Offline

    desht

    I think I can guess where line 78 is - the first line inside onEnable().

    You've declared your FileConfiguration object, but you haven't actually initialised it to anything. So it's null when you come to use it.
     
  5. Offline

    civ77

    lol sorry yes @desht guessed right, I didn't know objects needed to be initialised, thanks everyone.
    Edit: now I'm getting another error:
    Code:
    2012-01-10 17:10:34 [SEVERE] Error occurred while enabling ExpBank v0.3 (Is it up to date?): java.lang.Integer cannot be cast to java.lang.Double
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
    	at me.hayden.expbank.ExpBank.onEnable(ExpBank.java:84)
    	at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:228)
    	at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:970)
    	at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:280)
    	at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:186)
    	at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:169)
    	at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:348)
    	at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:335)
    	at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:165)
    	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:399)
    	at net.minecraft.server.ThreadServerApplication.run(SourceFile:457)
    I'm always completely lost when I try to convert data types...
     
  6. Offline

    iPhysX

    Code:
    java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Double
    
    at me.hayden.expbank.ExpBank.onEnable(ExpBank.java:84)
    Check over the Int/Doubles you are using on this line?
     
  7. Offline

    civ77

    there are no ints only doubles, so I dont know what the problem is.
     
  8. Offline

    iPhysX

    Are you reading from the config, and something is being treated as INT in the config?
     
  9. Offline

    civ77

    it apears that all entries in the config are objects not ints ot Doubles

    BUMP

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

    desht

    Well, why are you tring to use doubles in the first place? Presumably your "bank" co-ordinates are those of a block (not an entity), so integers are all you need here. You've even supplied integers (0, 64, 0) for the co-ordinate defaults.

    (You're getting the class cast exception because the FileConfiguration get() method is returning Integer objects to you, and those cannot be cast directly to Double).
     
    civ77 likes this.
  11. Offline

    civ77

    Oh, thanks, I was being a bit (very) stupid. The Double thing is a remnant of an old failed attempt at doing something related.
     
Thread Status:
Not open for further replies.

Share This Page