I want to add Admob Banner ad with SurfaceView but it gives NullPointerException, Here is code:
private AdView mAdView; private LinearLayout ll; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ll = new LinearLayout(this); mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder() .build(); mAdView.loadAd(adRequest); ll.addView(mAdView); ll.addView(new GamePanel(this)); setContentView(ll); } GamePanel is a class that extends SurfaceView and implements SurfaceHolder
Error says:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference at com.example.binnat.zigzag.MainActivity.onCreate(MainActivity.java:54) line 52: mAdView.loadAd(adRequest);