Problem creating properties...

Discussion in 'Plugin Development' started by creatorfromhell, Aug 25, 2012.

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

    creatorfromhell

    Hello,
    I wrote some code that I wrote to create a properties file, but when my application runs it throws java.lang.NullPointerException. My properties file code is:

    Code:
            @SuppressWarnings({ "unchecked", "rawtypes" })
    public TreeMap<String, Kit> kits = new TreeMap();
     
    ArcadianPlugin plugin;
     
    public KitCommandExecutor(ArcadianPlugin plugin) {
    this.plugin = plugin;
    }
     
    //Create & load kit.properties. Create other necessary files.
        public void loadKits() {
            kits.clear();
            Properties props = new Properties();
            props.setProperty("trainee", "17 64;-600");
           
            File f = new File(plugin.getDataFolder() + "/config/", "kits.properties");
            if (!f.exists()) {
                try {
                    props.store(new FileOutputStream(f), "Format: KitName=ItemId1; ItemId2;-cooldown(in seconds)");
                } catch (IOException e) {
              plugin.getLogger().severe(e.getMessage());
                }
            } else {
          try {
                    props.load(new FileInputStream(f));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
           
            for (Entry<?, ?> e : props.entrySet()) {
                String key = (String) e.getKey(), value = (String) e.getValue();
                this.kits.put(key.toLowerCase(), new Kit(key.toLowerCase(), value));
            }
        }
    To test that this was the cause of the error I put this i my main class:

    Code:
        KitCommandExecutor ke;
     
        onEnable() {
        try {
    ke.loadKits();
    } catch (Exception e) {
      getLogger().severe(e.toString());
    }
        }
    Thanks in advance for any and all help.
     
  2. Offline

    Courier

  3. Offline

    sd5

    I think your KitCommandExecutor ke is not initialized
     
  4. Offline

    creatorfromhell

    Thanks so much. Turns out I just had to change KitCommandExecutor ke to KitCommandExecutor ke = new KitCommandExecutor(); Like you said.
     
  5. Offline

    Firefly

    I'm surprised your IDE didn't say it wasn't initialized.
     
  6. Offline

    creatorfromhell

    Actually, I'm quite surprised Eclipse did not pick it up myself. Eclipse didn't even show any warning none the less that it wasn't initialized.
     
Thread Status:
Not open for further replies.

Share This Page