title: Java nullpointerexception for a 2D scrolling game
body: <p>I'm making a game, its 2D side scrolling, kinda like terraria. In my game, i have offsets, <code>XOff</code> and <code>YOff</code>, and those move the terrain. I also have a method for my character, <code>move()</code>, and all that does is this:</p>
  
  <pre><code>public void move() {
          if (!ableToMove) //makes sure you can move
              return;
          // x += moveX; these 2 methods work, but x and y are just my player coords.
          // y += moveY;
          core.setYOff(1); //core is my main class, where the global variables are stored
      }
  </code></pre>
  
  <p>the comments label and describe each variable. so, setYOff(1) sets the <code>YOff</code> like so:</p>
  
  <pre><code>private void setYOff(int i){
       YOff += i;
  }
  </code></pre>
  
  <p>Now, there is only one way that i am accessing the <code>move</code> method. in a thread, called <code>PlayerThread</code>, i have a constant call to the <code>move()</code> and another method called <code>applyGravity()</code>, which doesnt really have a relevance to this question. That is in the <code>PlayerThread</code>.</p>
  
  <p>Now here is the problem i'm having... When I call the <code>setYOff()</code>, I'm getting the following error:</p>
  
  <pre><code>Exception in thread "player Thread" java.lang.NullPointerException
      at main.Player.move(Player.java:33)
      at main.PlayerThread.run(PlayerThread.java:24)
      at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>which is telling me that when i'm calling the <code>setYOff()</code> method in my <code>move()</code> method, it doesnt work. I've tried just testing and moving the call to set the Y offset into the thread itself, and it gives the same error... I then tried to move it to the <code>RefreshThread</code>, and interestingly it did work... it moved the entire map down 1 pixel every 20 milliseconds... and i have no clue why! what is wrong with my move method that makes this not work, or better yet, my <code>PlayerThread</code>, that isnt making this work in the long run? What is different about my <code>RefreshThread</code>? If you guys need the entire code for everything involving the calls, creation, and such of each thread, i can provide that, but i'm not sure you would need that... What do i need to do differently? Thanks in advance!</p>
  
  <p><strong>EDIT:</strong> I tried, in my <code>PlayerThread</code> just commenting out the <code>move()</code> call, and just having it adjust the y offset, and it worked! so it has to do with the move method, but again, why?</p>
  
  <p><strong>CORRECTION TO PREVIOUS EDIT:</strong> so testing more, i put the <code>move()</code> call back into the thread, and kept the <code>setYOff(1)</code> in it, and it still worked, but again not from within the move method itself...</p>