title: Java Stack push method NullPointerException
body: <p>I'm implementing a Character Buffer with two stacks. I am inserting an element with insert() method:</p>
  
  <pre><code>class Buffer
  {
      private Stack&lt;Character&gt; stackLeft;
      private Stack&lt;Character&gt; stackRight;
      private int size;
  
      Buffer()
      {
          Stack&lt;Character&gt; stackLeft   = new Stack&lt;Character&gt;();
          Stack&lt;Character&gt; stackRight  = new Stack&lt;Character&gt;();
          size = 0;
      }
  
      public void insert(char c)
      {
          size ++;
          stackLeft.push(c); //This line returns NullPointerException
      }
  }
  </code></pre>
  
  <p>Everytime it tries to push the c character variable, it throws Null pointer exception.
  Here's how I have called it from main:</p>
  
  <pre><code>public static void main(String[] args)
  {
      Buffer tb = new Buffer();
  
      Character ch = new Character('a');
      tb.insert(ch);
      tb.insert(new Character('a'));
      tb.insert('a');
  }
  </code></pre>
  
  <p>All of these return a null exception. Asserted that Character reaches inside the method fine. I used java.util.Stack; when it failed, I implemented my own. But it still failed.<br>
  What could I be doing wrong?<br>
  Any kind of help is appreciated!</p>