Solved Need help with "file cannot be null"

Discussion in 'Plugin Development' started by OneBillionAndOne, Jul 16, 2013.

Thread Status:
Not open for further replies.
  1. Alright, ive posted alot of these lately xD. Anyways, every time i execute the command "ctfsetredsapwn" or anything that has to do with the config, it causes an error on the console and in the game.
    error:
    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'ctfsetredflag' in plugin Ctf v0.0.1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:189)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.dispatchCommand(CraftServer.java:523)
        at net.minecraft.server.v1_6_R2.PlayerConnection.handleCommand(PlayerConnection.java:964)
        at net.minecraft.server.v1_6_R2.PlayerConnection.chat(PlayerConnection.java:882)
        at net.minecraft.server.v1_6_R2.PlayerConnection.a(PlayerConnection.java:839)
        at net.minecraft.server.v1_6_R2.Packet3Chat.handle(SourceFile:49)
        at net.minecraft.server.v1_6_R2.NetworkManager.b(NetworkManager.java:296)
        at net.minecraft.server.v1_6_R2.PlayerConnection.e(PlayerConnection.java:118)
        at net.minecraft.server.v1_6_R2.ServerConnection.b(SourceFile:37)
        at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
        at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
        at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203)
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
        at org.gmail.firework4lj.onCommand.setup.onCommand(setup.java:48)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
        ... 15 more
    on of the commands in the command executer class (called setup):
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. Player player = (Player) sender;
    3. Location loc = player.getLocation();
    4. if(cmd.getName().equalsIgnoreCase("ctfsetspawn")){
    5. getConfig().set("location.Worldspawn" , loc.getWorld());
    6. getConfig().set("location.Xspawn" , loc.getX());
    7. getConfig().set("location.Yspawn" , loc.getY());
    8. getConfig().set("location.Zspawn" , loc.getZ());
    9. getConfig().set("location.Yawspawn" , loc.getYaw());
    10. getConfig().set("location.Pitchspawn" , loc.getPitch());
    11. player.sendMessage(ChatColor.GOLD+"Main spawn set!");
    12. }

    and the onenable function in the main class:
    Code:java
    1. @Override
    2. public void onEnable(){
    3. FileConfiguration config = this.getConfig();
    4. config.options().copyDefaults(true);
    5. saveDefaultConfig();
    6. getCommand("ctfstart").setExecutor(new CtfonCommand(this));
    7. getCommand("ctfred").setExecutor(new CtfonCommand(this));
    8. getCommand("ctfblue").setExecutor(new CtfonCommand(this));
    9. getCommand("ctfleave").setExecutor(new CtfonCommand(this));
    10. getCommand("ctfdebugteam").setExecutor(new CtfonCommand(this));
    11. getCommand("classes").setExecutor(new CtfClasses(this));
    12. getCommand("soldier").setExecutor(new CtfClasses(this));
    13. getCommand("sniper").setExecutor(new CtfClasses(this));
    14. getCommand("scout").setExecutor(new CtfClasses(this));
    15. getCommand("heavy").setExecutor(new CtfClasses(this));
    16. getCommand("medic").setExecutor(new CtfClasses(this));
    17. getCommand("ctfsetspawn").setExecutor(new setup(this));
    18. getCommand("ctfsetredspawn").setExecutor(new setup(this));
    19. getCommand("ctfsetbluespawn").setExecutor(new setup(this));
    20. getCommand("ctfsetredflag").setExecutor(new setup(this));
    21. getCommand("ctfsetblueflag").setExecutor(new setup(this));
    22. PluginManager pm = getServer().getPluginManager();
    23. this.getServer().getPluginManager().registerEvents(new EntityDamageByEntityEventListener(this), this);
    24. this.getServer().getPluginManager().registerEvents(new FlagpickupListener(this), this);
    25. this.getServer().getPluginManager().registerEvents(new Grenade(this), this);
    26. this.getServer().getPluginManager().registerEvents(new Cancelexplosion(this), this);
    27. this.getServer().getPluginManager().registerEvents(new ChatInterface(), this);
    28. this.getServer().getPluginManager().registerEvents(new Blockinteract(), this);
    29. getLogger().info("Ctf has been enabled");
    30. }

    Any help appriciated! thanks!

    oh and forgot, heres the config:
    Code:
    # Default config
    location.Worldredflagspawn:
    location.Xredflagspawn:
    location.Yredflagspawn:
    location.Zredflagspawn: 
    Thanks

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  2. Offline

    xTrollxDudex

    OneBillionAndOne
    Put this
    PHP:
    this.saveDefaultConfig();
    Before ANYTHING in your on enable
     
  3. xTrollxDudex
    still getting same error :(

    anyone have a better fix?

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

    Rocoty

    tell me....does setup by any chance extend JavaPlugin?
    If yes: That's your problem (not directly)
    If no: More code, please?
     
  5. Rocoty
    yes it does, by more code, i can give you the top of setup and one of the commands, although i dont really want to give out the whole class code :p unless its necessary. but its basically the same as the first command. heres setup:
    Code:java
    1. package org.gmail.firework4lj.onCommand;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandExecutor;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.configuration.file.FileConfiguration;
    11. import org.bukkit.configuration.file.YamlConfiguration;
    12. import org.bukkit.entity.Player;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14. import org.gmail.firework4lj.CtfMain;
    15.  
    16. public class setup extends JavaPlugin implements CommandExecutor{
    17.  
    18. public setup(CtfMain ctfmain){
    19. }
    20.  
    21.  
    22. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    23. Player player = (Player) sender;
    24. Location loc = player.getLocation();
    25. if(cmd.getName().equalsIgnoreCase("ctfsetspawn")){
    26. getConfig().set("location.Worldspawn" , loc.getWorld());
    27. getConfig().set("location.Xspawn" , loc.getX());
    28. getConfig().set("location.Yspawn" , loc.getY());
    29. getConfig().set("location.Zspawn" , loc.getZ());
    30. getConfig().set("location.Yawspawn" , loc.getYaw());
    31. getConfig().set("location.Pitchspawn" , loc.getPitch());
    32. player.sendMessage(ChatColor.GOLD+"Main spawn set!");
    33. }
     
  6. Offline

    Sagacious_Zed Bukkit Docs

    OneBillionAndOne You must only extend JavaPlugin once in your whole plugin.
     
  7. Offline

    Polaris29

    OneBillionAndOne Like Sagacious_Zed said, you can only have one class extending JavaPlugin in your plugin. If CtfMain is your plugin's main class, then put the field "CtfMain ctfMain;" in your setup class and then put "this.ctfMain = ctfMain" in setup's constructor then use "ctfMain.getConfig()".

    Just extending JavaPlugin won't make everything magically work out, the class needs to be properly intialized by Bukkit's plugin loader which is why there's the "main:" thing in your plugin.yml. If you have a class extending JavaPlugin that isn't your main class, it's pretty much just an empty shell with, I'm guessing that many of it's variables would be equal to null.
     
  8. Sagacious_Zed Polaris29
    Thank you! it works now, i had extend javaplugin in all my classes, and i guess this was the first one to cause a problem, but i fixed all that, and it seems to be working. thank-you!
     
Thread Status:
Not open for further replies.

Share This Page