File cannot be null?

Discussion in 'Plugin Development' started by hankered, Jun 10, 2014.

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

    hankered

    Hey. Please help, ever since I added a list to the config, I got the following stacktrace:

    My stacktrace:
    Code:java
    1. [16:05:24 ERROR]: Could not load 'plugins\Crates.jar' in folder 'plugins'
    2. org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Fi
    3. le cannot be null

    My code:
    Code:java
    1. public void loadConfig(){
    2.  
    3. FileConfiguration config = this.getConfig();
    4.  
    5. List<String> donorchest1 = config.getStringList("crates.donorchest1.rewards");
    6. List<String> donorchest = config.getStringList("crates.donorchest.rewards");
    7. List<String> randomchest = config.getStringList("crates.randomchest.rewards");
    8. donorchest1.add("EMERALD_ORE");
    9. donorchest.add("EMERALD_ORE");
    10. randomchest.add("EMERALD_ORE");
    11.  
    12. config.addDefault("crates.donorchest1.Z", 0);
    13. config.addDefault("crates.donorchest1.Y", 50);
    14. config.addDefault("crates.donorchest1.X", 0);
    15. config.addDefault("crates.donorchest1.world", "world");
    16. config.addDefault("crates.donorchest1.keyname", "key1");
    17. config.addDefault("crates.donorchest1.rewards", donorchest1);
    18.  
    19. config.addDefault("crates.donorchest.Z", 1);
    20. config.addDefault("crates.donorchest.Y", 50);
    21. config.addDefault("crates.donorchest.X", 1);
    22. config.addDefault("crates.donorchest.world", "world");
    23. config.addDefault("crates.donorchest.keyname", "key1");
    24. config.addDefault("crates.donorchest.rewards", donorchest);
    25.  
    26. config.addDefault("crates.randomchest.Z", 2);
    27. config.addDefault("crates.randomchest.Y", 50);
    28. config.addDefault("crates.randomchest.X", 2);
    29. config.addDefault("crates.randomchest.world", "world");
    30. config.addDefault("crates.randomchest.keyname", "key1");
    31. config.addDefault("crates.randomchest.rewards", randomchest);
    32.  
    33.  
    34.  
    35. this.getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
    36. this.saveConfig();
    37. }
    38.  
     
  2. Offline

    AmShaegar

    Please post the whole stacktrace...
     
  3. Offline

    hankered

    AmShaegar
    Code:java
    1. [16:05:24 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.2-R0.
    2. 2-b2974jnks (MC: 1.7.2) (Implementing API version 1.7.2-R0.2)
    3. [16:05:24 ERROR]: Could not load 'plugins\Crates.jar' in folder 'plugins'
    4. org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Fi
    5. le cannot be null
    6. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    7. ava:182) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    8. at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    9. java:308) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    10. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    11. .java:231) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    12. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.ja
    13. va:255) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    14. at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:23
    15. 3) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    16. at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [c
    17. raftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    18. at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14
    19. ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    20. at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.jav
    21. a:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    22. at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    23. :424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    24. at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    25. 17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    26. Caused by: java.lang.IllegalArgumentException: File cannot be null
    27. at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbu
    28. kkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    29. at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(Yam
    30. lConfiguration.java:171) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    31. at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:118) ~
    32. [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    33. at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[cr
    34. aftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    35. at me.hankered.crates.Crates.<init>(Crates.java:23) ~[?:?]
    36. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    37. ~[?:1.7.0_40]
    38. at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    39. ~[?:1.7.0_40]
    40. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    41. rce) ~[?:1.7.0_40]
    42. at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_4
    43. 0]
    44. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    45. ava:178) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    46. ... 9 more


    Sorry.
     
  4. Offline

    AmShaegar

    There is something wrong with your config. Looks like you are accessing it too early or something like that. I bet you are using it wrong or on a constructor. Please post the whole main class.
     
  5. Offline

    1Rogue Retired Staff

    Don't extend JavaPlugin in more than one class and don't set any fields using "getConfig()" in your main class like so:

    Code:java
    1. public class MyPlugin extends JavaPlugin {
    2.  
    3. private final String myString = getConfig().getString("doh"); // Bad!
    4.  
    5. }
     
Thread Status:
Not open for further replies.

Share This Page