Can't figure out NullPointerException when I run my tests : <p>I keep getting a null pointer exception and I can't seem to figure out why.  I'm running some tests and that is when I get the null pointer exception, however, when I run it from Pangrams main(), I get no problems whatsoever.  I've included the code, tests and stack trace below.  Any help would be greatly appreciated and thanks in advance!</p>

<pre><code>import java.util.Map;
import java.util.TreeMap;

public class Pangrams {
    private static TreeMap&lt;Character, Integer&gt; letterCount;

    public static void main(String[] args) {
        Pangrams pan = new Pangrams();
        System.out.println(pan.isPangram("the quick brown fox jumps over the lazy dog"));
        pan.getLetterCount();
    }

    public Pangrams() {
        letterCount = new TreeMap&lt;&gt;();
        populateMap();
    }

    public static boolean isPangram(String text) {

        if(text.length() &lt; 26) return false;

        addToMap(text);

        for(Map.Entry&lt;Character, Integer&gt; entry : letterCount.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
            if(!(entry.getValue() &gt;= 1)) {
                return false;
            }
        }

        return true;
    }

    public static void populateMap() {
        for(char x = 'a'; x &lt;= 'z'; x++) {
            letterCount.put(Character.valueOf(x), 0);
        }
    }

    public static void addToMap(String text) {
        char[] textArray = text.toLowerCase().replace(" ", "").toCharArray();
        // System.out.println(textArray.length);

        for(char letter : textArray) {
            if(letterCount.containsKey(letter)) {
                int count = letterCount.get(letter);

                letterCount.put(letter, ++count);
                System.out.println(letterCount.get(letter));
            }
            else if(!Character.isWhitespace(letter)) {
                letterCount.put(letter, 1);
            }
        }
    }

    public static void getLetterCount() {
        for(Map.Entry&lt;Character, Integer&gt; entry : letterCount.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue());
        }
    }
}
</code></pre>

<p>Here are the tests:</p>

<pre><code>import org.junit.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;

public class PangramTest {

    @Test
    public void emptySentence() {
        assertFalse(Pangrams.isPangram(""));
    }

    @Test
    public void testLowercasePangram() {
        assertTrue(Pangrams.isPangram("the quick brown fox jumps over the lazy dog"));
    }

    @Test
    public void missingCharacterX() {
        assertFalse(Pangrams.isPangram("a quick movement of the enemy will jeopardize five gunboats"));
    }

    @Test
    public void mixedCaseAndPunctuation() {
        assertTrue(Pangrams.isPangram("\"Five quacking Zephyrs jolt my wax bed.\""));
    }

    @Test
    public void nonAsciiCharacters() {
        assertTrue(Pangrams.isPangram("Victor jagt zwölf Boxkämpfer quer über den großen Sylter Deich."));
    }

}
</code></pre>

<p>Here is the full stack trace:</p>

<pre><code>java.lang.NullPointerException
    at Pangrams.addToMap(Pangrams.java:47)
    at Pangrams.isPangram(Pangrams.java:24)
    at PangramTest.testLowercasePangram(PangramTest.java:15)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:117)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:42)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:253)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:84)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
</code></pre>
