IllegalArgumentException

Discussion in 'Plugin Development' started by Gator96100, Apr 1, 2012.

Thread Status:
Not open for further replies.
  1. Hi.
    I have a problem with my separate CommandExecutor class
    I use this code for loading an Integer from the config
    Code:
    private VoteEarn VE = new VoteEarn();
    Integer curr = VE.getConfig().getInt("user."+ sender.getName() + ".curr");
    In the main class it workes perfectly.
    Error Code:
    Code:
    [SCHWERWIEGEND] null
    org.bukkit.command.CommandException: Unhandled exception executing command 'vote
    ' in plugin VoteEarn v0.1
    Caused by: java.lang.IllegalArgumentException: File cannot be null
     
  2. Offline

    nisovin

    You're probably trying to do this before the plugin has been fully initialized. You can't access the config until onEnable is called.

    Edit: Actually, this is probably because you're creating a new instance of your main class. You can't do that, you need to use the real instance of your plugin class.
     
  3. And how shoud I do that?
    I don't want to put the full code in one Class.
     
  4. Offline

    CorrieKay

    its simple, just dont create a new version of your plugin.

    youre doing
    Code:
    private VoteEarn VE = new VoteEarn();
    Integer curr = VE.getConfig().getInt("user."+ sender.getName() + ".curr");
    just do,
    Code:
    Integer cur = getConfig().getInt("user."+ sender.getName() + ".curr");
     
    //or if youre NOT inside of your main class file:
     
    Integer cur = yourplugininstance.getConfig().getInt("user."+ sender.getName() + ".curr");
    If youre still getting a null exception, then that means youre setting your config before onEnable AKA as a declared class variable of your main class, or the result OF one of said variables.
     
  5. And how I can get my plugin instance?
     
  6. Offline

    CorrieKay

    you find a way to pass it from your main class file into the constructor of the new object, then store it in a variable there.
     
  7. Sry but I'm not good in developing.
    Can you pls give me one example?

    Edit: Can I use this:
    Code:
    getCommand("vote").setExecutor(CommandListener);
     
  8. Offline

    CorrieKay

    ... Do do you know what constructors are? or parameters?

    If not, no offense, then you should go back to learning java before developing plugins :x
     
  9. I konw that I have to learn java, but I need this plugin.
    And this config is the only think that is missing
     
  10. Offline

    CorrieKay

    watch this and this

    Using both constructors and parameters, you can create a constructor with a parameter of your plugin. Pass your plugin into the constructor via a parameter, and store it locally, to use from there.
     
  11. Thank you very much.
    You helped me a lot
     
Thread Status:
Not open for further replies.

Share This Page