NullPtrException Java using enum in Map
<p>I was trying an alternate way of doing some code I already have that I find unelegant and I met this exception. I don't really understand what's happening, I'm still very new to Java.</p>

<p>I'm sorry if there is a bit much code but I don't think I can cut much more. The exception is raised on the first line of <code>Initialize()</code>.</p>

<p>Here is the exact error message:</p>

<blockquote>
  <p>Exception in thread "main" java.lang.NullPointerException     at
  simulationia.CritterInfo.Initialize(Critter.java:35)  at
  simulationia.SimulationIA.main(SimulationIA.java:21)</p>
</blockquote>

<p>Line 35 is the first line of <code>Initialize()</code>. Line 21 of SimulationIA is the call to <code>Initialize()</code>.</p>

<pre><code>// Critter.java
class CritterInfo { 
    static private Map&lt;Object, String&gt; enum_desc;

    public enum CRITTER_TYPE { CT_HERBIVORE, CT_CARNIVORE }
    public enum CRITTER_STATE { CS_FULL, CS_HUNGRY, CS_STARVING, CS_DEAD }

    /* ... */

    static void Initialize() {
        enum_desc.put((Object)CRITTER_TYPE.CT_HERBIVORE,    "Herbivore");
        enum_desc.put((Object)CRITTER_TYPE.CT_CARNIVORE,    "Carnivore");
        enum_desc.put((Object)CRITTER_STATE.CS_FULL,        "Full");
        enum_desc.put((Object)CRITTER_STATE.CS_HUNGRY,      "Hungry");
        enum_desc.put((Object)CRITTER_STATE.CS_STARVING,    "Starving");
        enum_desc.put((Object)CRITTER_STATE.CS_DEAD,        "Dead");
    }

    /* ... */
}   
</code></pre>

<p>The other file...</p>

<pre><code>// SimulationIA.java
public class SimulationIA {
    public static void main(String[] args) {
        /* ... */

        CritterInfo.Initialize();

        /* ... */
    }
}
</code></pre>

<p>Basically what I am trying to do is to have one single map to hold all enum values without caring about its type and having to check with <code>instanceof</code>. Maybe this is just not doable.</p>

<p>Edit: I think this may have to do with the fact that I do not use actual objects, only values of the enum hence it complaining about null pointer. Is that right ? How would I go around this ?</p>
