title: Android : surfaceView cannot getHolder() in onCreate(), must in onResume()
body: <p>In my activity, I has some views and a <code>surfaceView</code>.</p>
  
  <p>Here is my first code in <code>onCreate()</code></p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      upBtn = (Button) findViewById(R.id.upBtn);
      // and more widget here
      surface = (SurfaceView) findViewById(R.id.surfaceView);     
      this.holder = surface.getHolder(); // NullPointerException
      setContentView(R.layout.view);
  </code></pre>
  
  <p>If I change the above code by taking <code>surfaceView</code> and <code>getHolder()</code> in <code>onResume()</code> (I have tried many times to have this result), no error:</p>
  
  <pre><code>public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      upBtn = (Button) findViewById(R.id.upBtn);
      // and more widget here
      // surface = (SurfaceView) findViewById(R.id.surfaceView); //cancel     
      // this.holder = surface.getHolder(); // cancel
      setContentView(R.layout.view);
  </code></pre>
  
  <hr>
  
  <pre><code>public void onResume() {
      surface = (SurfaceView) findViewById(R.id.surfaceView);     
      this.holder = surface.getHolder(); // No Error now
  </code></pre>
  
  <p>Please explain for me.</p>