Solved All my getConfig() wrapper methods return null

Discussion in 'Plugin Development' started by ron975, Oct 28, 2012.

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


    Like the title says, no matter what I do, all my getConfig() wrappers return null.

    I'm building against Bukkit 1.3.2 R-1.1 BTW

    For example, I have this YAML file
    2. items:
    3. pumpkin:
    4. enabled: true
    5. healFoodAmount: 1
    6. healHealthAmount: 0
    7. itemAmount: 10
    8. potionEffects:
    9. - regen
    10. potionStrength:
    11. regen: 1
    12. potionDuration:
    13. regen: 1
    14. messageOnEat: 'You nibbled on some seeds'
    15. messageInsufficient: 'Too..little..seeds..must..satisfy..cravings!'
    16. messageUnable: 'Doesnt seem like you are able to nibble on any seeds'

    and this is an example of my getter.
    2. public String getUnableMessage(String type){
    3. String unableMessage = plugin.getConfig().getString("items."+type+".messageUnable");
    4. return unableMessage;
    5. }

    and I'm using this code to debug
    3. try
    4. {
    5. getLogger().info(config.getUnableMessage("pumpkin"));
    6. }
    7. catch (Exception e)
    8. {
    9. // TODO Auto-generated catch block
    10. getConfig().set("items.pumpkin.messageUnable", "[DEBUG] NOT ENOUGH MESSAGE GOES HERE");
    11. saveConfig();
    12. e.printStackTrace();
    13. }

    Now, this throws an NPE when using the getUnableMessage() method, but when I use the normal bukkit getConfig().getString(), it works fine. I don't see anything wrong with my wrapper methods.. Someone help please?

    Full source of my plugin here
  2. Offline

    Sagacious_Zed Bukkit Docs

    entire stack trace will be helpful for you to determine what is causing the exception
  3. Offline


    im gonna go out on a limb and take a random guess.

    Your type string in the config is lowercase, are you using something like, getUnableMessage(itemStack.getType().name());?

    If so, try setting it to lowercase, name().toLowerCase()
  4. Offline


    I'm manually passing the string to the method, i.e.

    As for full stack trace, if I put
    in my onEnable()
    2. 8:10:08 PM [SEVERE] Error occurred while enabling PumpkiNibble v1.0 (Is it up to date?)
    3. at net.mystia.PumpkiNibble.PumpkiNibbleMain.onEnable(
    4. at
    5. at
    6. at org.bukkit.plugin.SimplePluginManager.enablePlugin(
    7. at org.bukkit.craftbukkit.CraftServer.loadPlugin(
    8. at org.bukkit.craftbukkit.CraftServer.enablePlugins(
    9. at net.minecraft.server.MinecraftServer.i(
    10. at net.minecraft.server.MinecraftServer.d(
    11. at net.minecraft.server.MinecraftServer.a(
    12. at net.minecraft.server.DedicatedServer.init(
    13. at
    14. at
  5. Offline

    Sagacious_Zed Bukkit Docs

    the variable config is null. As far as i can tell your alternating between the variable config which you should not have, and the method call.
  6. Offline


    config is a reference to my getters class. However, I guess for this I should be using static-access anyways, so I'll try using a static method.
  7. Offline

    Sagacious_Zed Bukkit Docs

    config should never be static access.
  8. Offline


    Take a look at my source code, specifically

    config is not an instance of my configuration, but an instance of (or in this case,, which contains all my wrapper methods.
  9. Offline


    Solving this, all I had to do was make my API methods static, I also did
    private static ConfigurationSection config = PumpkiNibbleMain.p.getConfig();
    Just in case.
Thread Status:
Not open for further replies.

Share This Page