Why is this returning null?

Discussion in 'Plugin Development' started by jolbol1, Oct 25, 2015.

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

    jolbol1

    Code:
    private FileConfiguration customConfig;
    private File customConfigFile;
    
    
    public void reloadCustomConfig(){
    if (!customConfigFile.exists()){
    plugin.saveResource("portals.yml", false);
    
    }
    
    customConfigFile = new File(plugin.getDataFolder(), "portals.yml");
    customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    
    for.InputStream defConfigStream = plugin.getResource("portals.yml");
    if(defConfigStream != null){
    YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    customConfig.setDefaults(defConfig);
    }
    }
    It returns null on line 6.

    I've tried:
    Code:
    private FileConfiguration customConfig;
    private File customConfigFile;
    
    
    public void reloadCustomConfig(){
    customConfigFile = new File(plugin.getDataFolder(), "portals.yml");
    if (!customConfigFile.exists()){
    plugin.saveResource("portals.yml", false);
    
    }
    
    
    customConfig = YamlConfiguration.loadConfiguration(customConfigFile);
    
    for.InputStream defConfigStream = plugin.getResource("portals.yml");
    if(defConfigStream != null){
    YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
    customConfig.setDefaults(defConfig);
    }
    }
    But it still returns null. Any help is appreciated.
     
  2. Offline

    scrollbar

    In your first block of code, you don't show the initialization section. In the second block of code, the initialization looks correct. A null pointer exception would be thrown from either the plugin variable which I would assume you did correctly or the portals.yml file not existing which would also through a null pointer exception. Here is a wrapper that I use for configs so you could check some of the code there: https://github.com/ZavCoding/ZavAut...a/com/zavteam/plugins/utils/CustomConfig.java
     
Thread Status:
Not open for further replies.

Share This Page