Cannot make a static reference to the non-static field

Discussion in 'Spigot Plugin Development' started by Lutheron, May 26, 2018.

  1. Hello, and i have a problem. My problem is as the title says.
    Im making a rankup sign plugin.

    With the public string ARankName, im trying to get the value from RankName1, which get it's value from a config file.

    Code (Text):
    public class SignListener implements Listener {
            public int ASignPrice = 10000;
            public int BSignPrice = 50000;
            public int CSignPrice = 100000;
            public String ARankName = SignRankup.RankName1;
            public String BRankName = "C";
            public String CRankName = "B";
            public String DRankName = "A";
    Code (Text):
    public class SignRankup extends JavaPlugin {

         public String RankName1 = getConfig().getString("RankName1");
         public String RankName2 = getConfig().getString("RankName2");
         public String RankName3 = getConfig().getString("RankName3");
         public String RankName4 = getConfig().getString("RankName4");  
         public int SignPrice1 = (getConfig().getInt("SignPrice1"));
         public int SignPrice2 = (getConfig().getInt("SignPrice1"));
         public int SignPrice3 = (getConfig().getInt("SignPrice1"));
         public static Economy econ = null;
         public void onEnable() {
             Bukkit.getServer().getPluginManager().registerEvents(new SignListener(), this);
             if (!setupEconomy()) {
                 this.getLogger().severe("Disabled due to no Vault dependency found!");
             FileConfiguration config = getConfig();
             config.addDefault("RankName1", "D");
             config.addDefault("RankName2", "C");
             config.addDefault("RankName3", "B");
             config.addDefault("RankName4", "A");
             config.addDefault("SignPrice1", 10000);
             config.addDefault("SignPrice2", 50000);
             config.addDefault("SignPrice3", 100000);
         public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
             if (!(sender instanceof Player)) {
                     sender.sendMessage(ChatColor.RED + "The console cannot use Rankup Sign!");
                     return true;
             return true;
         private boolean setupEconomy() {
                if (Bukkit.getPluginManager().getPlugin("Vault") == null) {
                    return false;
                RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
                if (rsp == null) {
                    return false;
                econ = rsp.getProvider();
                return econ != null;
            public static Economy getEconomy() {
                return econ;
    • Funny Funny x 1
  2. Don't use static, learn to use construction methods and when coding an API, you can use static
  3. public String ARankName = SignRankup.RankName1;

    You'll either need to make this static, not recommended or pass SignRankup class to your listener class and reference it that way
  4. woops works now after closing and opening the server.

    Thanks for the help.