NullpointerException

Discussion in 'Plugin Development' started by callum.thepro, May 25, 2013.

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

    callum.thepro

    I have a nullpointer exception which is found at this class at line 108, I cant squash this so help would be useful

    Code:
    public static void startGame(String arena) {
     
            Bukkit.getServer().broadcastMessage("worked!");
            File path = new File(plugin.getDataFolder() + "/Arena");
            File data = new File(path, "Arenas.yml");
            YamlConfiguration arenas = new YamlConfiguration();
     
            if (!(path.exists())) {
                path.mkdir();
            }
           
            if(!(data.exists())) {
                try {
                    data.createNewFile();
                } catch (IOException e) {
                    System.out.println("Failed to create file");
                }
            }
           
                try {
                    arenas.load(data);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (InvalidConfigurationException e) {
                    e.printStackTrace();
                }       
           
           
            Bukkit.getServer().broadcastMessage("Worked!");
     
            int i = 1;
     
            for (Player p : plugin.getServer().getOnlinePlayers()) {
                int x = arenas.getInt("arenas.list." + arena + ".spawns.list." + i + ".location.x");
                int y = arenas.getInt("arenas.list." + arena + ".spawns.list." + i + ".location.y");
                int z = arenas.getInt("arenas.list." + arena + ".spawns.list." + i + ".location.z");
                String s = arenas.getString("arenas.list." + arena + ".location.world");
     
                i++;
     
                World world = Bukkit.getServer().getWorld(s);
     
                Location loc = new Location(world, x, y, z);
     
                p.sendMessage(x + ", " + y + ", " + z + ", " + world.getName());
                plugin.ingame.put(p.getName(), true);
                plugin.lives.put(p.getName(), 3);
     
                p.teleport(loc);
     
            }
        }
    Is broadcast's Worked once and not twice meaning it does not get past the first stage
     
  2. Offline

    chasechocolate

    What is line 108?
     
  3. Offline

    callum.thepro

    File path = new File(plugin.getDataFolder() + "/Arena");

    It is on a timer and works when it runs the second time though so i am really confused
     
  4. Offline

    Timatooth

    The only thing that would explain that NPE is that the variable plugin is null i.e hasn't been initialized/assigned at that point. Also make sure that method startArena needs to be static since you might be trying to access instance data.
     
Thread Status:
Not open for further replies.

Share This Page