Java HashMap.put throwing NullPointerException with "new" keyword : <p>I have checked everywhere for a solution to this problem and simply cannot find one despite its apparent simplicity.</p>

<p>I keep getting a <code>NullPointerException</code> when calling <code>myFunction()</code>:</p>

<pre><code>private static Map&lt;String, Map&lt;String, Integer&gt;&gt; data;

public Class() {
    data = new Map&lt;String, Map&lt;String, Integer&gt;();
}

public static void myFunction(String key, String val0, int val1) {
    boolean createNewEntry = false;
    if(null == data) {
        createNewEntry = true;
    }
    else if(!data.containsKey(key)) {
        createNewEntry = true;
    }
    if(createNewEntry) {
        data.put(key, new HashMap&lt;String, Integer&gt;()); // This throws a NullPointerException.
    }
    data.get(key).put(val0, data.get(key).get(val0) + val1);
}
</code></pre>

<p>The stack trace (with some project-specific data removed) is as follows:</p>

<pre><code>Could not pass [Event] to [JAR file] v1.0.0
org.[parent].event.EventException
    ... (irrelevant)
Caused by: java.lang.NullPointerException
    at net.[package name].[class].myFunction([source file].java:93)
    at net.[package name].[class].otherFunction([source file].java(108)
    at net.[package name].[other class].anotherFunction([other file].java(65)
    at net.[package name].[main class].on[Event]([main file].java:97) ~[?:?]
    at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:[versioning number]]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:[versioning number]]
    at org.[a different package name].plugin.java.JavaPluginLoader$1.execute([a file].java:301) ~[[versioning number]:[more data]]
    ... 15 more
</code></pre>

<p>Thank you in advance for any insight into this problem.</p>
