title: NullPointerException when accessing Boolean Java
body: <p>I have a <code>boolean</code> which checks if an action is to be performed or not, the <code>boolean</code> is being being accessed through <code>setters and getters</code>, I have other <code>booleans</code> am accessing in a similar way and they are not giving me any errors except this one, at first I was checking it in a piece of code within a seperate thread and that part was not working without producing an exception so I put it in a <code>toggleButton</code> just to do a simple <code>read</code> and <code>write</code> on it, then the <code>nullPointerException</code> came up, here is my code I have commented it</p>
  
  <pre><code>toggleButton.setOnMousePressed(new EventHandler&lt;MouseEvent&gt;() {
          @Override public void handle(MouseEvent event) {
           //this part is executing perfectly
           //meaning my toggleButton is ok
           System.out.println("Toggle Button Clicked");
  
           //this is where I am getting the NullPointerException
           if(!getblackAndWhite()){
  
              setblackAndWhite(true);
  
           }else{
  
                setblackAndWhite(false);
  
            }
          }});
  
  
  private void setblackAndWhite(Boolean blackAndWhite)
  
  {
      this.blackAndWhite = blackAndWhite;
  }
  
  private Boolean getblackAndWhite()
  {
      return this.blackAndWhite;
  }
  </code></pre>