NullPointerException error, I can't find the error!

Discussion in 'Plugin Development' started by Geekhellmc, Aug 23, 2014.

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

    Geekhellmc

    So NullPointerException is:
    Thrown when an application attempts to use null in a case where an object is required. These include:
    • Calling the instance method of a null object.
    • Accessing or modifying the field of a null object.
    • Taking the length of null as if it were an array.
    • Accessing or modifying the slots of null as if it were an array.
    • Throwing null as if it were a Throwable value.
    So my problem is in the SignManager at line 35 and in the main class at line 19.

    Main Class:

    Code:
    package me.Geekhellmc.SSB;
     
    import me.Geekhellmc.SSB.listeners.BlockBreak;
    import me.Geekhellmc.SSB.listeners.PlayerDamage;
    import me.Geekhellmc.SSB.listeners.PlayerDeath;
    import me.Geekhellmc.SSB.listeners.PlayerInteract;
    import me.Geekhellmc.SSB.listeners.PlayerLeave;
    import me.Geekhellmc.SSB.listeners.PlayerLoseHunger;
    import me.Geekhellmc.SSB.listeners.SignManager;
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SSB extends JavaPlugin{
       
        public void onEnable(){
            Bukkit.getServer().getPluginManager().registerEvents(new SignManager(), this); //The line 19! But i don't get an error! Or figure out something

    SignManager Class:

    Code:
    package me.Geekhellmc.SSB.listeners;
     
    import java.util.ArrayList;
    import java.util.HashMap;
     
    import me.Geekhellmc.SSB.Arena;
    import me.Geekhellmc.SSB.ArenaManager;
    import me.Geekhellmc.SSB.LocationUtil;
    import me.Geekhellmc.SSB.MessageManager;
    import me.Geekhellmc.SSB.SettingsManager;
    import me.Geekhellmc.SSB.MessageManager.MessageTypie;
     
    import org.bukkit.Location;
    import org.bukkit.block.Sign;
    import org.bukkit.configuration.ConfigurationSection;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.block.SignChangeEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
     
    public class SignManager implements Listener{
     
        private static HashMap<Sign, Integer> signs = new HashMap<Sign, Integer>();
     
        public SignManager(){
            if (!SettingsManager.getLobbySigns().contains("signs")){
                SettingsManager.getLobbySigns().createConfigurationSection("signs");
            }
     
            for (String str : SettingsManager.getLobbySigns().<ConfigurationSection>get("signs").getKeys(true)){
                ConfigurationSection section = SettingsManager.getLobbySigns().get("signs." + str);
     
                Location loc = LocationUtil.locationFromConfig(section.getConfigurationSection("location"), false);
                Sign s = (Sign) loc.getBlock().getState(); //The line 35! Also not getting an error or figuring out something :(
     
  2. Offline

    ulsa

    Can you post the whole error please :)
    also try looking if loc isn't null
     
  3. Offline

    Geekhellmc

    ulsa you mean all the class? I just showed where the stack trace shows me the error line.
     
  4. Offline

    ulsa

    *tried to mean if you can post the trace
    but it looks like you are trying to get location from a configurationsection so I think that variable loc may be null at that point because it couldnt get a location or anything .. just before executing try to check if it is null
    Code:java
    1. if(loc==null){/*print an error*/}
     
  5. Offline

    Geekhellmc

    ulsa I did not understand you code.
     
  6. Offline

    es359

    Please post the Stacktrace and more of your code, or we can't help you.
     
  7. Offline

    ulsa

    Use this code before the loc and re try.. if you see the message "it is null" that means loc is null
    Code:java
    1. if(loc==null){Bukkit.broadcastMessage("it is null");}
     
Thread Status:
Not open for further replies.

Share This Page