What cannot be null!?

Discussion in 'Plugin Development' started by CraftCreeper6, Apr 15, 2014.

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

    CraftCreeper6

    Hello! So my plugin wont load...
    Code:
    Code:java
    1. package me.CraftCreeper6.All;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin{
    13.  
    14. // This is for easy access if you type p.sendMessage(pn + "__") ingame it would display as [AdvertiseMe] __
    15. // Got it?
    16.  
    17. private String pn = ChatColor.GOLD + "[" + ChatColor.GREEN + "Advertise" + ChatColor.RED + "Me" + ChatColor.GOLD + "] " + ChatColor.BLUE;
    18.  
    19. Object OnGoing = getConfig().get("OnGoingAds");
    20.  
    21. public static ArrayList<String> HasAd = new ArrayList<String>();
    22.  
    23. public void onEnable(){
    24.  
    25. System.out.print("AdvertiseMe has been enabled sucessfuly!");
    26.  
    27. }
    28. public void onDisable(){
    29.  
    30. System.out.print("AdvertiseMe has been disabled succesfully!"); // It's not that bad... Plus it works better -_- You don't need to create a PDF file for EVERY plugi
    31. }
    32.  
    33. public boolean onCommand(CommandSender sender, Command cmd,
    34. String commandLabel, final String[] args) {
    35. Player p = (Player) sender;
    36. if (commandLabel.equalsIgnoreCase("advertise")) {
    37.  
    38. if (args.length == 0) {
    39. p.sendMessage(pn + ChatColor.RED + "Not enough arguments! Type /advertise help for a list of commands!");
    40. } else {
    41. if (args[0].equalsIgnoreCase("help")){
    42. p.sendMessage(pn + "Base command: /advertise");
    43. p.sendMessage(pn + "/advertise help - Display help");
    44. p.sendMessage(pn + "/advertise price - Display the amount of cost each time the advertisement is shown");
    45. p.sendMessage(pn + "/advertise create [Amount of times] [Advertisement name] [Advertisement Message] - Display your advertisement");
    46. p.sendMessage(pn + "/advertise list - List the current Advertisement");
    47. p.sendMessage(pn + "/advertise duration - How long the Advertisement will be displayed for (Monthly, Weekly)");
    48.  
    49. } else if (args[0].equalsIgnoreCase("list")){
    50.  
    51. p.sendMessage(pn + "The current Advertisements are:");
    52. p.sendMessage(pn + OnGoing);
    53.  
    54. } else if (args[0].equalsIgnoreCase("create")){
    55.  
    56. getConfig().set("OnGoingAds", p.getName() + args[2]);
    57.  
    58. p.sendMessage(pn + "You advertisement has been added to the queue! It will be displayed very soon!");
    59.  
    60. saveConfig();
    61.  
    62. final String name = args[1];
    63.  
    64. //String builder for args
    65.  
    66. StringBuilder sb = new StringBuilder();
    67. for(int n=3; args[n]!=null; n++)
    68. sb.append(args[n]+" ");
    69. final String message = sb.toString();
    70.  
    71. //Scheduler for timings (60 secs atm)
    72.  
    73. Bukkit.getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    74. public void run(){
    75. Bukkit.broadcastMessage(pn + name + message);
    76. }
    77. }, 120);
    78.  
    79. }
    80.  
    81. }
    82. }
    83. return true;
    84. }
    85. }


    StackTrace:
    Code:
    [23:49:02] [Server thread/ERROR]: Could not load 'plugins\AdvertMe.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: File cannot be null
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:308) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:231) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.loadPlugins(CraftServer.java:255) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.<init>(CraftServer.java:233) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.PlayerList.<init>(PlayerList.java:63) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.DedicatedPlayerList.<init>(SourceFile:14) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.init(DedicatedServer.java:126) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:424) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
    Caused by: java.lang.IllegalArgumentException: File cannot be null
        at org.apache.commons.lang.Validate.notNull(Validate.java:203) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:171) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:118) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:112) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        at me.CraftCreeper6.All.Main.<init>(Main.java:19) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_45]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_45]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_45]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_45]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-b2974jnks]
        ... 9 more
    
    Any help apreciated! I don't understand "File cannot be null" It wont even tell me the file name D:
     
  2. Offline

    LegoPal92

    It is saying that your config is null. You are using a null object, just set the variable in the onenable.
     
  3. Offline

    CraftCreeper6

    LegoPal92
    Ok thanks! Didn't realise :p

    LegoPal92
    Still doesn't work :/
    Code:
    Code:java
    1. getConfig().set("Enabler", 1);
    2. saveConfig();
    3.  


    I added that to the onEnable^^

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

    LegoPal92

    What is that supposed to do? All that does is set the line: Enabler: 1 in the config. What you need to do is have your variable initialized in your config.
     
  5. Offline

    CraftCreeper6

    LegoPal92
    I fixed it :)
    It was to do with my Eclipse not exporting properly!
     
Thread Status:
Not open for further replies.

Share This Page