ConfigManager NPE

Discussion in 'Plugin Development' started by superchris05326, Apr 24, 2015.

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

    superchris05326

    I have a NPE in my config manager class on line 18 which is:

    Code:
    public static List<Integer> i = plugin.getConfig().getIntegerList("Items");
    Here is the rest of my code:

    Code:
    package me.superchris05326.loot;
    
    import java.util.List;
    import java.util.Random;
    
    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    
    public class ConfigManager {
       
        public static Plugin plugin;
       
        public ConfigManager(Plugin plugin){
            this.plugin = plugin;
        }
       
        public static List<Integer> i = plugin.getConfig().getIntegerList("Items");
       
        public static ItemStack getRandomItem(){
            Random random = new Random();
            int rn = random.nextInt(i.size());
            return new ItemStack(Material.getMaterial(i.get(rn)));
        }
    }
    
    As well as my configuration file:

    Code:
    Items:
      - 311
      - 276
      - 278
     
  2. Offline

    mythbusterma

    @superchris05326

    Why is everything static......? That's why you're having all these issues. Make the fields private and non-static, then initilise them in the constructor.
     
    Konato_K and (deleted member) like this.
  3. Offline

    superchris05326

    If it's not static all of my methods become errored out.
    @mythbusterma
     
  4. Offline

    teej107

  5. Offline

    Konato_K

    @superchris05326 Then you need to learn java.

    For your issue, plugin is null.
     
Thread Status:
Not open for further replies.

Share This Page