NPE on getConfig()

Discussion in 'Plugin Development' started by jkcclemens, Dec 9, 2011.

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

    jkcclemens

    I'm trying to implement config files and userdata into my plugin, but upon starting I get this:
    Code:
    17:23:49 [SEVERE] Error occurred while enabling RoyalCommands v0.0.3 (Is it up to date?): null
    java.lang.NullPointerException
            at tk.royalcraf.royalcommands.RoyalCommands.loadConfiguration(RoyalCommands.java:42)
            at tk.royalcraf.royalcommands.RoyalCommands.onEnable(RoyalCommands.java:62)
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:188)
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:968)
            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)
    
    Code:
    17:23:52 [INFO] This server is running Craftbukkit version git-Bukkit-1.8.1-R4-99-g893d9d9-b1572jnks (MC: 1.0.1) (Implementing API version 1.0.0-R1-SNAPSHOT)
    
    And of course, here's the java file:

    Code:
    ...
    
    
    	public void loadConfiguration() {
    		plugin.getConfig().options().copyDefaults(true); // line 42
    		plugin.saveConfig();
    		File file = new File(plugin.getDataFolder() + "/userdata/");
    		boolean exists = file.exists();
    		if (!exists) {
    			try {
    				boolean success = new File(plugin.getDataFolder() + "/userdata")
    						.mkdir();
    				if (success) {
    					log.info("[RoyalCommands] Created userdata directory.");
    				}
    			} catch (Exception e) {
    				log.severe("[RoyalCraft] Failed to make userdata directory!");
    				log.severe(e.getMessage());
    			}
    		}
    	}
    
    	public void onEnable() {
    
    		loadConfiguration(); //line 62
    
    		PluginManager pm = this.getServer().getPluginManager();
    
    ...
    
    I cannot find why it NPEs on plugin.getConfig().options().copyDefaults(true);.

    --
    Running on Debian 6 64-bit.

    config.yml in jar:
    Code:
    
    ## RoyalCommands v0.0.3 Config File
    
    # Whether to disable /getip command (also disables /compareip)
    disabled_getip: false
    
     
  2. Try updating your Bukkit AND CraftBukkit
     
  3. Offline

    DomovoiButler

    its config.yml not config.xml
    EDIT: and also, the comments in the config.yml will not be copied, thats why i hate copyDefaults
     
  4. Offline

    Lolmewn

    Yup, this probably is your problem.
     
  5. Offline

    jkcclemens

    Thanks, but I accidentally wrote xml in the post, I have config.yml in my jar.

    The jar is here if you want to try it. Just in case.
     
  6. Offline

    DomovoiButler

    is this loadCofiguration method in the main class? why its plugin.getConfig?
     
  7. Offline

    jkcclemens

    Compiled using newest Bukkit release from ci.bukkit, still same NPE.

    Well that was stupid of me. Changing it to this.getConfig fixes the NPE. I forgot I was making it in the main class. Thanks for catching my error, I probably never would have.

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

    DomovoiButler

    xD, np...thats what my first guess but i didnt think anyone would do this kind of error(no offence)
    and sometimes when i suggest stuff i always end up being wrong and critisized by someone so i didnt post right away
     
Thread Status:
Not open for further replies.

Share This Page