title: OnSetContentView not working in andengine with admob
body: <p>I've been trying to implement admob into my andengine game. I have used the following codes for the setting of the views. The <code>onSetContentView()</code> gives me no errors in my other game but gives the following errors in my other game.</p>
  
  <pre><code>@Override
  protected void onSetContentView() {
      //Creating the parent frame layout:
      final FrameLayout frameLayout = new FrameLayout(this);
      //frameLayout.
      //Creating its layout params, making it fill the screen.
      final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT,
                      FrameLayout.LayoutParams.FILL_PARENT);
  
     System.out.println("enter on setContentview");
  
     final AdView adView = new AdView(this, AdSize.BANNER, "a14fb36149e903c");
          adView.refreshDrawableState();
              adView.setVisibility(AdView.VISIBLE);
  
              try{
  
                    // Create an ad request.
                     AdRequest adRequest = new AdRequest();
                    // Set&lt;String&gt; s = "AdRequest.TEST_EMULATOR ";
  
  
                     adRequest.addTestDevice("E20D4AA1FE0CA3F46CD22145AD392B87");
                     // Fill out ad request.
  
                     // Add the AdView to the view hierarchy. The view will have no size
                     // until the ad is loaded.
  
                    // Start loading the ad in the background.
                 adView.loadAd(adRequest);
              }catch(Exception e){
                  System.out.println("this si the error"+e.toString());
              }
      //Creating the banner layout params. With this params, the ad will be placed in the bottom of the screen, middle horizontally.
      final FrameLayout.LayoutParams bannerViewLayoutParams =
              new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
                      FrameLayout.LayoutParams.WRAP_CONTENT,
                      Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
  
  
  
  
  
      //Creating AndEngine's view.
      this.mRenderSurfaceView = new RenderSurfaceView(this);
      mRenderSurfaceView.setRenderer(this.mEngine);
  
      System.out.println("enter on setContentview 2222");
      //createSurfaceViewLayoutParams is an AndEngine method for creating the params for its view.
      final android.widget.FrameLayout.LayoutParams surfaceViewLayoutParams =
              new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
  
      //Adding the views to the frame layout.
      frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
     // frameLayout.addView(adView, bannerViewLayoutParams);
  
      System.out.println("enter on setContentview 2198613948632");
      //Setting content view
      this.setContentView(frameLayout, frameLayoutLayoutParams);
  
      System.out.println("enter on setContentview 33344");
  }
  </code></pre>
  
  <p>codes with the onSetContentView i get a fatal error as follows:</p>
  
  <pre><code>05-16 11:56:42.421: E/AndroidRuntime(18552): java.lang.NullPointerException
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at org.anddev.andengine.ui.activity.BaseGameActivity.doResume(BaseGameActivity.java:179)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at org.anddev.andengine.ui.activity.BaseGameActivity.onWindowFocusChanged(BaseGameActivity.java:85)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2056
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.view.View.dispatchWindowFocusChanged(View.java:3788)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:658)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.view.ViewRoot.handleMessage(ViewRoot.java:1930)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.os.Handler.dispatchMessage(Handler.java:99)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.os.Looper.loop(Looper.java:143)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at android.app.ActivityThread.main(ActivityThread.java:4701)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at java.lang.reflect.Method.invokeNative(Native Method)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at java.lang.reflect.Method.invoke(Method.java:521)05-16 11:56:42.421: E/AndroidRuntime(18552):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:859)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:617)
  05-16 11:56:42.421: E/AndroidRuntime(18552):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>I am using the onSetContentView exactly the same way as Jong suggested. furthermore, i tried debugging, and i realised that the first scene in my game is run, but before going to the second scene it crashes. my codes for the frist scene are as follows</p>
  
  <pre><code>@Override
  public Scene onLoadScene() {
  
       sceneGameSplash = new Scene();
  
      System.out.println("size of height and width is : "+this.getHeight + "   "+this.getWidth);
  
  
  
      final Sprite spriteGameSplash = new Sprite(0, 0,
              gameSplashScreenRegion);
  
      spriteGameSplash.setWidth(display.getWidth());
  
      spriteGameSplash.setHeight(display.getHeight());
  
      sceneGameSplash.attachChild(spriteGameSplash);
  
  
      sceneGameSplash.registerUpdateHandler(new TimerHandler(5f, true,
              new ITimerCallback() {
  
                  @Override
                  public void onTimePassed(final TimerHandler pTimerHandler) {
                      System.out.println("5");
                      sceneGameSplash.unregisterUpdateHandler(pTimerHandler);
                      sceneGameSplash.detachChildren();
                      sceneGameSplash.clearTouchAreas();
                      sceneManagerUnjumble.loadMain();
  
                  }
              }));
  
  
      System.out.println("6");
      return sceneGameSplash;
  }
  </code></pre>
  
  <p>Anybody with any idea on why there is a nullPointerException </p>