title: Android: onCreate boolean not changing
body: <p>In an android application that I am developing Im using a thread, and to make sure I dont get the "java.lang.IllegalStateException: System services not available to Activities before onCreate()" I use a boolean called donecreate. Problem is that Android studio says I have a "java.lang.NullPointerException at picLoop.run(picLoop.java:24)"</p>
  
  <p>Code main class:</p>
  
  <pre><code>import android.app.Activity;
  import android.content.pm.ActivityInfo;
  import android.media.AudioManager;
  
  import android.os.Bundle;
  import android.view.Display;
  
  import android.view.Window;
  import android.view.WindowManager;
  import android.widget.Toast;
  
  
  public class main extends Activity {
  public Boolean donecreate;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
      requestWindowFeature(Window.FEATURE_NO_TITLE);
      getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
              WindowManager.LayoutParams.FLAG_FULLSCREEN);
      setContentView(new eyeCanvas(this));
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
      docreate();
  }
  public void docreate(){
      donecreate = true;
  }
  public void checkHead(){
      AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
      if(am.isWiredHeadsetOn()){
          Toast.makeText(getApplicationContext(), "HEADPHONES",         Toast.LENGTH_LONG).show();
      }
      }
  
  
  
  }
  </code></pre>
  
  <p>Code: pic loop</p>
  
  <pre><code>import android.graphics.Canvas;
  
  
  
  //**Threading
  public class picLoop extends Thread {
  private eyeCanvas eye;
  private main main = new main();
  public picLoop(eyeCanvas eye) {
      this.eye = eye;
  }
  
  @Override
  public void run(){
  
  
      Canvas c = null;
  
  while(true) {
  if(main.donecreate){ //&lt;-- where error is
  main.checkHead();
  }
  
  try {
    //  head.onCreate(Bundle savedInstanceState);
      c = eye.getHolder().lockCanvas();
      synchronized (eye.getHolder()) {
          eye.onDraw(c);
      }
  } finally {
      if (c != null) {
          eye.getHolder().unlockCanvasAndPost(c);
      }
  }
  
  try {
      sleep(1000);
  } catch (InterruptedException e) {
      e.printStackTrace();
   }
  
   }
     }
  
     }
  </code></pre>
  
  <p>Also if you guys could give me feedback on how I submitted, It would help :) </p>