Solved arenamanager problems

Discussion in 'Spigot Plugin Development' started by AwsomeCoder, May 31, 2018.

  1. hello people, i just cant figure out why the arena name is null, it shows zero error, just a null when i print the arena name. help would be nice.

    Manager
    Code (Text):
      public void  createarena(Player p ,String name, int min_players,int max_players){
            File f = new File(FileManager.Getinstance().arenadir + File.separator + name + ".yml");
            if(f.exists()){p.sendMessage(ChatColor.RED + "a arena with that name already exists");}
            FileConfiguration config = YamlConfiguration.loadConfiguration(f);
            config.set("name",name);
            config.set("min_players", min_players);
            config.set("max_players", max_players);
            Arena arena = new Arena(name);
            arenas.add(arena);
            try{
                config.save(f);
            } catch(Exception ex){
                ex.printStackTrace();
            }
        }


        public void loadarenas(){
            for (File file : new File(plugin.getDataFolder().getAbsolutePath() + File.separator + "arenas").listFiles()) {
                if(!file.exists()){
                    return;
                }
                FileConfiguration config = YamlConfiguration.loadConfiguration(file);
                String name = config.getString("name");
                int min_players = config.getInt("min_players");
                int max_players = config.getInt("max_players");
                Arena a = new Arena(name);
                System.out.print(a.getName());
                arenas.add(a);


                }
            }

        public Arena getArena(String name){
            for(Arena arena : arenas){
                if(arena.getName().equalsIgnoreCase(name)){
                    return arena;
                    }
            }
            return null;
        }
     
  2. Which line has the error?
     
  3. the System.out.print(a.getName()); just says null, that it
     
  4. Your Arena-Object is null
     
  5. If the arena obj would be null then a NPE would be thrown.

    Could you please share your Arena class?
     
  6. Excuse me, my fault. Then...

    1. Something is wrong in your Arena Object (name not initialized)
    2. The String in your parameter is null.