title: Why is java giving me this NullPointerException?
body: <p>Ok, so I've been using Eclipse to work on making a Bukkit plugin for Minecraft. For some reason, I have been getting a lot of seemingly unreasonable NullPointerExceptions. I found that NullPointerExceptions occur when you attempt to use a the values and functions of the type of a varriable whose value is null. I could not find it in my code, so I wanted to see if someone else could find it.</p>
  
  <p>Error:</p>
  
  <pre><code>20:16:58 [SEVERE] java.lang.NullPointerException
  20:16:58 [SEVERE]       at com.tommy3244.plugins.MakeYourOwnBlocks.MakeYourOwnBl
  ocks.onDisable(MakeYourOwnBlocks.java:73)
  20:16:58 [SEVERE]       at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlug
  in.java:219)
  20:16:58 [SEVERE]       at org.bukkit.plugin.java.JavaPluginLoader.disablePlugin
  (JavaPluginLoader.java:481)
  20:16:58 [SEVERE]       at org.bukkit.plugin.SimplePluginManager.disablePlugin(S
  implePluginManager.java:400)
  20:16:58 [SEVERE]       at org.bukkit.plugin.SimplePluginManager.disablePlugins(
  SimplePluginManager.java:393)
  20:16:58 [SEVERE]       at org.bukkit.plugin.SimplePluginManager.clearPlugins(Si
  mplePluginManager.java:434)
  20:16:58 [SEVERE]       at org.bukkit.craftbukkit.v1_4_6.CraftServer.reload(Craf
  tServer.java:563)
  20:16:58 [SEVERE]       at org.bukkit.Bukkit.reload(Bukkit.java:184)
  20:16:58 [SEVERE]       at org.bukkit.command.defaults.ReloadCommand.execute(Rel
  oadCommand.java:23)
  20:16:58 [SEVERE]       at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCo
  mmandMap.java:186)
  20:16:58 [SEVERE]       at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchCom
  mand(CraftServer.java:514)
  20:16:58 [SEVERE]       at org.bukkit.craftbukkit.v1_4_6.CraftServer.dispatchSer
  verCommand(CraftServer.java:506)
  20:16:58 [SEVERE]       at net.minecraft.server.v1_4_6.DedicatedServer.al(Dedica
  tedServer.java:260)
  20:16:58 [SEVERE]       at net.minecraft.server.v1_4_6.DedicatedServer.r(Dedicat
  edServer.java:225)
  20:16:58 [SEVERE]       at net.minecraft.server.v1_4_6.MinecraftServer.q(Minecra
  ftServer.java:494)
  20:16:58 [SEVERE]       at net.minecraft.server.v1_4_6.MinecraftServer.run(Minec
  raftServer.java:427)
  20:16:58 [SEVERE]       at net.minecraft.server.v1_4_6.ThreadServerApplication.r
  un(SourceFile:849)</code></pre>
  
  <p>And here is my actual plugin code:</p>
  
  <pre><code>package com.tommy3244.plugins.MakeYourOwnBlocks;<br/><br/>import java.io.File;<br/>import java.util.*;<br/><br/>import org.bukkit.block.*;<br/>import org.bukkit.command.*;<br/>import org.bukkit.configuration.ConfigurationSection;<br/>import org.bukkit.entity.Player;<br/>import org.bukkit.event.*;<br/>import org.bukkit.event.block.Action;<br/>import org.bukkit.event.player.PlayerInteractEvent;<br/>import org.bukkit.inventory.ItemStack;<br/>import org.bukkit.inventory.meta.ItemMeta;<br/>import org.bukkit.plugin.java.JavaPlugin;<br/><br/>public class MakeYourOwnBlocks extends JavaPlugin implements Listener<br/>{<br/>    public Map&lt;NewItem, List&lt;ItemStack&gt;&gt; items;<br/>    public File configfile;<br/>    @SuppressWarnings(&quot;unchecked&quot;)<br/>   public void onEnable()<br/> {<br/>      try<br/>        {<br/>          Map&lt;List&lt;Map&lt;String, Object&gt;&gt;, NewItem&gt; smap;<br/>            smap = SaveLoadAPI.load(this.getDataFolder().getPath()+&quot;\\Items.data&quot;);<br/>          for(List&lt;Map&lt;String, Object&gt;&gt; maps : smap.keySet())<br/>            {<br/>              NewItem item = smap.get(maps);<br/>             List&lt;ItemStack&gt; stacks = new ArrayList&lt;ItemStack&gt;();<br/>               for(Map&lt;String, Object&gt; map : maps)<br/>              {<br/>                  stacks.add(ItemStack.deserialize(map));<br/>                }<br/>              items.put(item, stacks);<br/>           }<br/>      }<br/>      catch(Exception e)<br/>     {<br/>          items = new HashMap&lt;NewItem, List&lt;ItemStack&gt;&gt;();<br/>       }<br/>      try<br/>        {<br/>          this.getDataFolder().mkdirs();<br/>     }<br/>      catch(Exception e)<br/>     {<br/>          <br/>       }<br/>      configfile = new File(getDataFolder(), &quot;config.yml&quot;);<br/>        if(!configfile.exists())<br/>       {<br/>          saveResource(&quot;config.yml&quot;, false);<br/>       }<br/>      try<br/>        {<br/>          getConfig().load(configfile);<br/>      }<br/>      catch(Exception error)<br/>     {<br/>          getLogger().severe(&quot;Could not load config!&quot;);<br/>            error.printStackTrace();<br/>       }<br/>      getServer().getPluginManager().registerEvents(this, this);<br/>     getLogger().info(&quot;MakeYourOwnBlocks successfully enabled!&quot;);<br/> }<br/>  public void onDisable()<br/>    {<br/>      try<br/>        {<br/>          Map&lt;List&lt;Map&lt;String, Object&gt;&gt;, NewItem&gt; smap = new HashMap&lt;List&lt;Map&lt;String, Object&gt;&gt;, NewItem&gt;();<br/>          for(NewItem item : items.keySet())<br/>         {<br/>              List&lt;ItemStack&gt; stacks = items.get(item);<br/>                List&lt;Map&lt;String, Object&gt;&gt; stacks2 = new ArrayList&lt;Map&lt;String, Object&gt;&gt;();<br/>              for(ItemStack stack : stacks)<br/>              {<br/>                  stacks2.add(stack.serialize());<br/>                }<br/>              smap.put(stacks2, item);<br/>           }<br/>          SaveLoadAPI.save(smap, this.getDataFolder().getPath()+&quot;\\Items.data&quot;);<br/>       }<br/>      catch (Exception e)<br/>        {<br/>          getLogger().severe(&quot;Was unable to save the items file to the default path of: &quot;+this.getDataFolder().getPath()+&quot;\\Items.data&quot;);<br/>            e.printStackTrace();<br/>       }<br/>  }<br/>  @EventHandler(priority = EventPriority.HIGHEST)<br/>    public void onItemStackRightClick(PlayerInteractEvent e)<br/>   {<br/>      Player player = e.getPlayer();<br/>     //getLogger().info(&quot;Player &quot;+player.getName()+&quot; has right clicked.&quot;);<br/>      for(NewItem item : items.keySet())<br/>     {<br/>          for(ItemStack curstack : items.get(item))<br/>          {<br/>              ItemMeta lore = ((ItemStack)curstack).getItemMeta();<br/>               List&lt;String&gt; lore2 = player.getItemInHand().getItemMeta().getLore();<br/>             if(lore == null || lore2 == null)<br/>              {<br/>                  getLogger().info(&quot;Pointer null!&quot;);<br/>                   if(lore == null)<br/>                   {<br/>                      getLogger().info(&quot;Pointer 1 null&quot;);<br/>                  }<br/>                  else<br/>                   {<br/>                      getLogger().info(&quot;Pointer 2 null&quot;);<br/>                  }<br/>              }<br/>              if(lore2.equals(lore))<br/>             {<br/>                  getLogger().info(player.getDisplayName()+&quot; right clicked with the same item!&quot;);<br/>                  boolean right = e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK;<br/>                  boolean block = e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK;<br/>                 boolean worked;<br/>                    if(right)<br/>                  {<br/>                      worked = item.onRightClick(player, right, block);<br/>                  }<br/>                  else<br/>                   {<br/>                      worked = item.onLeftClick(player, right, block);<br/>                   }<br/>                  if(!worked)<br/>                    {<br/>                      player.sendMessage(&quot;Script fault! Error raised.&quot;);<br/>                   }<br/>              }<br/>          }<br/>      }<br/>  }<br/>  public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)<br/>   {<br/>      if(sender instanceof Player)<br/>       {<br/>          <br/>       }<br/>      else<br/>       {<br/>          sender.sendMessage(&quot;You must be a player to perform this command!&quot;);<br/>         return false;<br/>      }<br/>      if(cmd.getName().equalsIgnoreCase(&quot;makeitem&quot;))<br/>       {<br/>          if(args.length &lt; 4)<br/>         {<br/>              return false;<br/>          }<br/>          String name = args[0];<br/>         String type = args[1];<br/>         String data = args[2];<br/>         String damage = args[3];<br/>           try<br/>            {<br/>              int dmg = Integer.parseInt(damage);<br/>                byte dta = (byte)Integer.parseInt(data);<br/>               int id = Integer.parseInt(type);<br/>               if(getConfig().contains(&quot;items.&quot;+name))<br/>              {<br/>                  ConfigurationSection section = getConfig();<br/>                    List&lt;List&lt;String&gt;&gt; lines = new ArrayList&lt;List&lt;String&gt;&gt;();<br/>                  lines.add(null);<br/>                   lines.add(null);<br/>                   if(getConfig().contains(&quot;items.&quot;+name+&quot;.onrightclick&quot;))<br/>                    {<br/>                      List&lt;String&gt; cur = getConfig().getStringList(&quot;items.&quot;+name+&quot;.onrightclick&quot;);<br/>                     lines.set(0, cur);<br/>                 }<br/>                  else<br/>                   {<br/>                      lines.set(0, null);<br/>                    }<br/>                  if(getConfig().contains(&quot;items.&quot;+name+&quot;.onleftclick&quot;))<br/>                 {<br/>                      List&lt;String&gt; cur = getConfig().getStringList(&quot;items.&quot;+name+&quot;.onleftclick&quot;);<br/>                      lines.set(1, cur);<br/>                 }<br/>                  else<br/>                   {<br/>                      lines.set(1, null);<br/>                    }<br/>                  List&lt;ItemStack&gt; stacks = new ArrayList&lt;ItemStack&gt;();<br/>                   ItemStack stack = new ItemStack(id, 1, dta);<br/>                   ItemMeta meta = stack.getItemMeta();<br/>                   meta.setDisplayName(name);<br/>                 List&lt;String&gt; lore;<br/>                   if(getConfig().contains(&quot;items.&quot;+name+&quot;.description&quot;))<br/>                 {<br/>                      lore = getConfig().getStringList(&quot;items.&quot;+name+&quot;.description&quot;);<br/>                    }<br/>                  else<br/>                   {<br/>                      lore = new ArrayList&lt;String&gt;();<br/>                  }<br/>                  lore.add(name);<br/>                    NewItem item = new NewItem(lore, name, id, dta, lines, dmg, false, section);<br/>                   meta.setLore(lore);<br/>                    stack.setItemMeta(meta);<br/>                   getLogger().info(stack.toString());<br/>                    stacks.add(stack);<br/>                 if(items == null)<br/>                  {<br/>                      getLogger().info(&quot;unused&quot;);<br/>                  }<br/>                  items.put(item, stacks);<br/>                   Player player = (Player)sender;<br/>                    player.getLocation().getWorld().dropItem(player.getLocation(), stack);<br/>                 player.sendMessage(&quot;Here you go!&quot;);<br/>              }<br/>              else<br/>               {<br/>                  sender.sendMessage(&quot;No configuration section at \&quot;&quot;+&quot;items.&quot;+name+&quot;\&quot;&quot;);<br/>                   return true;<br/>               }<br/>          }<br/>          catch(Exception error)<br/>         {<br/>              //sender.sendMessage(&quot;Error: &quot;+error.getLocalizedMessage());<br/>             //System.out.println(error);<br/>               //throw error;<br/>             //makeitem test 272 0 0<br/>                error.printStackTrace();<br/>               return true;<br/>           }<br/>          sender.sendMessage(&quot;Error: No command specified&quot;);<br/>       }<br/>      return true;<br/>   }<br/>}<br/></code></pre>
  
  <p>UPDATE:</p>
  
  <p>nakib answered my question, and the error is fixed! Thanks a lot!</p>