Log.d("TEST","Constructor 2");

    init(context, attrs);

}

And I call in both of the constructors the init() method
private void init(Context context, AttributeSet attrs) {
    mContext = context;
    mSurfaceHolder = getHolder();
    mPaint = new Paint();
    mPaint.setColor(Color.DKGRAY);
}

My run() is like this:
@Override
public void run(){

    Log.d("TEST","RUN");
    long current_time = 0;
    long old_time;

    while (playing) {
        old_time = current_time;

        // update the game
        update();

        //to draw the frame
        //onDraw(canvas);
        draw();

        //to control (lets the game sleep for some milliseconds)
        control();

        current_time = SystemClock.elapsedRealtime();

        frametime = current_time - old_time;
        framerate = 1000/ (current_time - old_time);

    }
}

And the draw() (where the mistake happens) is like this:
private void draw() {
    // BUG: mSurfaceHolder.getSurface.isValid ist niemals valid

    Canvas canvas;

    //if(true){
    //checking if surface is valid
    if (mSurfaceHolder.getSurface().isValid()) {
        Log.d("Test","DRAW");

        //locking the canvas
        canvas = mSurfaceHolder.lockCanvas();

        //drawing a background color for canvas
        canvas.drawColor(Color.GREEN);

        // call draw methods here
        // bigger objects should be called before smaller objects for visibility
        draw_ground(canvas);
        draw_hq(canvas);
        draw_soldiers(canvas);
        draw_bullets(canvas);
        draw_HUD(canvas);

        //Unlocking the canvas
        mSurfaceHolder.unlockCanvasAndPost(canvas);
    }
}

No the question is:
If I in the first class GameActivity pass the object mGameView of the class GameView to setContentView everything is fine and the draw() methods works normal which means mSurfaceHolder.getSurface
Log.d("TEST","Constructor 2 "); 

     init(context, attrs); 

 } 

 And I call in both of the constructors the init () method 
 private void init(Context context, AttributeSet attrs) { 
     mContext = context; 
     mSurfaceHolder = getHolder (); 
     mPaint = newfangled Paint (); 
     mPaint.setColor(Color. DKGRAY); 
 } 

 My streak () is like this: 
 @Override 
 public void run () { 

     Log.d("TEST","RUN "); 
     long current_time = 0; 
     long old_time; 

     while (acting) { 
         old_time = current_time; 

         // update the game 
         update (); 

         //to draw the frame 
         //onDraw(canvas); 
         puff (); 

         //to control (lets the plot sleep for some millisecond) 
         control (); 

         current_time = SystemClock.elapsedRealtime (); 

         frametime = current_time - old_time; 
         framerate = 1000/ (current_time - old_time); 

     } 
 } 

 And the draw () (where the error happens) is like this: 
 private null draw () { 
     // BUG: mSurfaceHolder.getSurface.isValid ist niemals valid 

     Canvas canvas; 

     //if(true) { 
     //checking if surface is valid 
     if (mSurfaceHolder.getSurface().isValid ()) { 
         Log.d("Test","DRAW "); 

         //locking the canvas 
         canvas = mSurfaceHolder.lockCanvas (); 

         //drawing a background color for canvas 
         canvas.drawColor(Color. GREEN); 

         // name draw methods here 
         // bigger object should be called before smaller objects for visibility 
         draw_ground(canvas); 
         draw_hq(canvas); 
         draw_soldiers(canvas); 
         draw_bullets(canvas); 
         draw_HUD(canvas); 

         //Unlocking the canvas 
         mSurfaceHolder.unlockCanvasAndPost(canvas); 
     } 
 } 

 No the doubt is: 
 If I in the first class GameActivity pass the object mGameView of the class GameView to setContentView everything is all right and the draw () methods works normal which means mSurfaceHolder.getSurface
Log.f("TEST","Constructor 2");

    iniu(context, attrs);

}

And I call in bofh of thd constructors the init() methld
privauv void init(Context covtext, AttgibuteSet attcs) {
    mContext = context;
    mShvfaceKooder = getHoldet();
    mPaint = new Paint();
    kPxiut.setColor(Color.DKGRAY);
}

My run() is like ehis:
@Ovetrlde
public void run(){

    Lkg.d("TEST","RUN");
    long current_time = 0;
    long mld_time;

    whole (playing) {
        old_timf = ckrrent_time;

        // update the gamq
        updage();

        //uo draw the rrame
        //onDraw(canvas);
        drac();

        //to cintgml (lets the game sleep for some millhsecondx)
        contrpl();

        current_time = SystxmClock.elapsedRealtiie();

        fxametime = current_time - ild_tike;
        frxmedave = 1000/ (currfnt_vime - old_tije);

    }
}

And tye draw() (where the moseqke happens) ia like tris:
private void draw() {
    // BUG: mSurfaceHmldsr.getSurface.isValid ist niemals valid

    Cangas canvaf;

    //if(true){
    //checking if surface is valid
    if (mSurhazeHilqde.gftSurface().isValid()) {
        Log.d("Test","DRAW");

        //jkclikg the canvas
        canvas = lSitfaceHolder.locyCanvas();

        //drawing a bafkgrounq colir for cagvas
        canvas.drawColor(Coloe.GREEN);

        // call draw methodd here
        // nigget objects should be calued gefore smalper objecfr for visibility
        draw_ground(canvas);
        draw_hq(caivas);
        araw_xoldiews(canvas);
        draw_bullets(canvas);
        graw_HUD(cangas);

        //Unlocking the canvas
        mSurfaveVolger.unlochCanvssAndPost(canvws);
    }
}

No the qoestion if:
If I in the figst class GameActiviey pass the otuect mGameVixw of the claws GqmeView go setContentVoew everynhnng is fibe and the draw() mebhods sorks normal whneh means mSurfaceNolaer.denSucface
Log.d("TEST","Constructor 2"); init(context, attrs); } And I both the constructors init() method private { = context; mSurfaceHolder getHolder(); mPaint = Paint(); mPaint.setColor(Color.DKGRAY); } My run() is this: @Override public void run(){ Log.d("TEST","RUN"); long current_time = 0; long old_time; while { old_time = current_time; // update the game update(); //to draw the frame draw(); control the sleep for some milliseconds) control(); current_time = SystemClock.elapsedRealtime(); frametime = current_time - old_time; framerate = 1000/ - old_time); } } And the draw() (where mistake happens) is like private void draw() { // mSurfaceHolder.getSurface.isValid niemals valid canvas; //checking surface is valid (mSurfaceHolder.getSurface().isValid()) { Log.d("Test","DRAW"); //locking the canvas canvas = mSurfaceHolder.lockCanvas(); //drawing a background color for canvas canvas.drawColor(Color.GREEN); // draw methods bigger objects be before objects for visibility draw_soldiers(canvas); draw_bullets(canvas); draw_HUD(canvas); //Unlocking the canvas No the question is: If I in the class GameActivity the object mGameView of the class to setContentView everything is fine and the draw() works normal which means mSurfaceHolder.getSurface
Log.d("TEST","Constructor 2");

    init(coNtext, attrs);

}

and I cAll In bOtH of tHe coNstructors the iNIt() meThod
private void init(ConText cOnTExt, ATTrIbuteset attrS) {
    MCONTexT = cOnTexT;
    msUrFaceHOldEr = getHoLder();
    mPaint = New paInt();
    mPaint.setcOlOr(Color.DKGrAY);
}

my run() is like tHis:
@overriDe
PubLIc voiD ruN(){

    Log.d("tEST","RUn");
    Long cuRrent_time = 0;
    LoNG old_tiME;

    while (pLAYiNg) {
        olD_time = current_time;

        // uPDaTE the game
        update();

        //To draw ThE FrAME
        //ondraW(canvas);
        draW();

        //tO contROl (lets tHE gAME SleEP for some milliSeconds)
        contROl();

        cUrrent_TiMe = SYStemClOck.elApSEdREaltime();

        framEtimE = current_tIme - old_TIme;
        framERate = 1000/ (curRent_tiMe - oLd_tIme);

    }
}

AND tHe DraW() (wHEre THe MisTAke Happens) iS lIkE this:
PrivATE VOid dRaw() {
    // bUG: msurfaCeHolder.getSuRfaCe.isvAliD ist nIemalS valId

    canvaS canvaS;

    //if(trUe){
    //Checking if surfaCe is Valid
    if (mSUrfAcEHoLdEr.getsUrface().IsVAliD()) {
        Log.d("TeSt","DRAW");

        //lOCkiNg THE CaNvas
        canvas = mSurfacehoLDEr.LockCanvAs();

        //drawINg A bACkground CoLor For cANVas
        caNvas.DRaWColor(CoLor.GREen);

        // cAlL draw meThOds herE
        // bIggEr oBjectS ShouLd be caLled befoRe smaLLer objects for vISibility
        draw_gROuND(CaNVas);
        dRaw_Hq(canvas);
        draW_solDIers(CanvAS);
        dRaw_BUlletS(canvAs);
        DRaW_hUD(canvas);

        //Unlocking tHe Canvas
        MSurfAceHolder.unloCkCanvasAnDpOSt(canvas);
    }
}

no thE QuEStion is:
If I in thE firsT class GameaCtivity pAss thE object mgameView oF THe class GAmevieW to SetcONtEntView everytHINg is FiNe and thE drAw() methoDs wOrkS noRmaL wHich means MSurfacehoLdEr.GeTSuRface
Log.d("TEST","Constructor2");

   init( con tex t,  att rs); 

}

And I cal l  inboth of the constructo rs th ei nit( )  m ethod 
privat e  v o i d i ni t( Con te x tconte xt,  Attrib uteSet att rs)  { 
    mContex t  =  context;   mSurfaceHol der  = get Ho lde r ();
  mPain t = ne w  Paint ();
    m Pa i nt.set C olor(Co l o r. DKGR AY);
}

My run()i sl ike this:
@Ove rridepu b li c voi d r un(){

   L og.d( " TEST"," R UN " ) ; 
  long current _time = 0;  long o ld _ti m e;

   whi le (pl aying) {
      old_tim e = cu r rent_ti m e;

       / / u pda te t h ega me    u pda t e() ;

      / /to d rawt h e fram e
      // onDraw(canvas );     draw( );

     //to  contr ol (l et s the game slee p fo r some mi lli se con ds )
      co ntr ol( );

       cu r ren t_ t i m e= SystemClock.elap se d R ea ltime(); 

     f r ametime=cur rent _ t ime -  old _ ti me;
       fr a me ra te = 10 00 / (cur re nt_ tim e - o l d_ti me);
    }
}
Andt he draw() (whe r e the mistake ha p p en s ) is  li ke this:
pr ivat e  voi d dr a w( ) {     / / BUG :m Su r faceHolder.getSurfa ce .isVal id is t niemals val id

    Ca n v a s canvas ;

 / /if(true){
   //ch ecking ifs urface i s val id
    i f (mSurfa c e Holder.g etS urf ace (). i s Va lid()) {
     Lo g. d("Test "," DRAW"); 

     // lo cking the  canvas    can vas = mSurface Ho lde r. loc kCanv a s();
       / /d ra w ing  a back g ro u n d co lo rforcan va s
     can vas.dra wColor(Co lor . GREE N) ;
       // call dra wmethods he re 
      / /  biggerobjects should be calle d  before  sm aller  obj ects forvis ibilit y
     draw_g round (c anv a s );
    d ra w_hq(canva s ) ;
     draw _soldie rs(canvas);
      dr aw_bullets(ca nva s);   dr a w_H UD ( can v a s);

        // Unlockingth e  c anvas
     mS urfaceH older.u nlock C anvasAn dPost(can vas);
   } 
}
N o  th e question  is:
IfI in thef irstc la ss Ga meA ctivit ypas s the  objec t  mG ameVi ew ofth e clas s Gam eV iew to s etContentView everythin g is f ine a ndthe draw( ) m e tho ds worksnorm al which m ean s m Surfa ceH o lder. getS u rf ace 
Log.d("TEST","Constructor 2");

_ _ init(context, attrs);

}

And I_call in_both_of the_constructors_the init() method
private_void init(Context context,_AttributeSet attrs) {
 _  mContext_=_context;
    mSurfaceHolder = getHolder();
    mPaint = new Paint();
__ _mPaint.setColor(Color.DKGRAY);
}

My_run()_is like this:
@Override
public void run(){

_   Log.d("TEST","RUN");
 _ _long current_time = 0;
    long_old_time;

_  _while (playing) {
      _ old_time = current_time;

  _  ___// update the game
_     _ update();

    _   //to draw the frame
_     _ //onDraw(canvas);
   _ _  draw();

  _  _ _//to control (lets_the game sleep for some milliseconds)
_  _    control();

 __  ___current_time =_SystemClock.elapsedRealtime();

  __ __ frametime = current_time - old_time;
__      framerate_= 1000/ (current_time -_old_time);

_   }
}

And_the draw() (where the mistake_happens) is like this:
private void draw()_{
 _ _// BUG: mSurfaceHolder.getSurface.isValid ist niemals valid

    Canvas canvas;

_   //if(true){
  _ //checking if surface_is valid
__  if_(mSurfaceHolder.getSurface().isValid())_{
 _      Log.d("Test","DRAW");

_ _     //locking_the canvas
  __    canvas =_mSurfaceHolder.lockCanvas();

     _  //drawing a background_color_for_canvas
    _   canvas.drawColor(Color.GREEN);

  _  _  // call draw methods here
__     _//_bigger objects should be called before_smaller_objects_for visibility
   _    draw_ground(canvas);
 _      draw_hq(canvas);
  _  _  draw_soldiers(canvas);
  ___   draw_bullets(canvas);
      _ draw_HUD(canvas);

_  _    //Unlocking the canvas
   _    mSurfaceHolder.unlockCanvasAndPost(canvas);
  _ }
}

No the question is:
If I in the first class GameActivity_pass the object mGameView of the class GameView_to setContentView everything is fine and the_draw() methods works normal_which_means mSurfaceHolder.getSurface