title: Attempt to invoke virtual method 'void com.google.android.gms.ads.AdView.loadAd(com.google.android.gms.ads.AdRequest)' on a null object reference
body: <p>i have been trying to show adbob banner ad in one of my activities but i keep getting this weird error, i tried doing different things but none of them helped fix the problem, i am stuck on this please help me fix this error, Thank you.
  here is the logcat</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rewardoapps.network/com.rewardoapps.network.ChatActivity}: 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 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
      at android.app.ActivityThread.-wrap11(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
      at android.os.Handler.dispatchMessage(Handler.java:105)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6541)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
   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.rewardoapps.network.ChatActivity.onCreate(ChatActivity.java:44)
      at android.app.Activity.performCreate(Activity.java:6975)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892) 
      at android.app.ActivityThread.-wrap11(Unknown Source:0) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593) 
      at android.os.Handler.dispatchMessage(Handler.java:105) 
      at android.os.Looper.loop(Looper.java:164) 
      at android.app.ActivityThread.main(ActivityThread.java:6541) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
  </code></pre>
  
  <p>here is my ChatActivity.java activity</p>
  
  <pre><code>public class ChatActivity extends ActivityBase implements MsgImageChooseDialog.AlertPositiveListener {
  private AdView AdView;
  
  Toolbar mToolbar;
  
  Fragment fragment;
  Boolean restore = false;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.activity_dialogs);
  
      mToolbar = (Toolbar) findViewById(R.id.toolbar);
  
      setSupportActionBar(mToolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      getSupportActionBar().setHomeButtonEnabled(true);
      MobileAds.initialize(this,
              "ca-app-pub-3940256099942544~3347511713");
  
      AdRequest adRequestBanner = new AdRequest.Builder().build();
      AdView = (AdView)this.findViewById(R.id.adView);
      AdView.loadAd(adRequestBanner);
  
      if (savedInstanceState != null) {
  
          fragment = getSupportFragmentManager().getFragment(savedInstanceState, "currentFragment");
  
          restore = savedInstanceState.getBoolean("restore");
  
      } else {
  
          fragment = new ChatFragment();
  
          restore = false;
      }
  
      FragmentManager fragmentManager = getSupportFragmentManager();
      fragmentManager.beginTransaction()
              .replace(R.id.container_body, fragment)
              .commit();
  }
  </code></pre>
  
  <p>.xml layout</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
  xmlns:ads="http://schemas.android.com/apk/res-auto"
  
  android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:orientation="vertical"
  tools:context="com.rewardoapps.network.ChatActivity" &gt;
  
      &lt;LinearLayout            android:id="@+id/container_toolbar"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:orientation="vertical"&gt;            &lt;include                android:id="@+id/toolbar"                layout="@layout/toolbar" /&gt;        &lt;/LinearLayout&gt;
  &lt;LinearLayout
      android:id="@+id/container_a"
      android:layout_width="match_parent"
      android:layout_height="50dp"
      android:background="#00ffffff"
      android:gravity="bottom|center_vertical|center_horizontal"
      android:orientation="vertical"
      android:visibility="visible"&gt;
  
      &lt;com.google.android.gms.ads.AdView
          android:id="@+id/adView"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          ads:adSize="BANNER"
          ads:adUnitId="ca-app-pub-3940256099942544/6300978111"&gt;&lt;/com.google.android.gms.ads.AdView&gt;
  &lt;/LinearLayout&gt;
  &lt;FrameLayout
      android:id="@+id/container_body"
      android:layout_width="fill_parent"
      android:layout_height="0dp"
      android:layout_weight="1"
      android:visibility="visible" /&gt;
  </code></pre>
  
  <p>
  here is the ActivityBase.java</p>
  
  <pre><code>public class ActivityBase extends AppCompatActivity implements Constants {
  
  public static final String TAG = "ActivityBase";
  
  private ProgressDialog pDialog;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
  
      initpDialog();
  }
  
  protected void initpDialog() {
  
      pDialog = new ProgressDialog(this);
      pDialog.setMessage(getString(R.string.msg_loading));
      pDialog.setCancelable(false);
  }
  
  protected void showpDialog() {
  
      if (!pDialog.isShowing()) {
  
          try {
  
              pDialog.show();
  
          } catch (Exception e) {
  
              e.printStackTrace();
          }
      }
  }
  
  protected void hidepDialog() {
  
      if (pDialog.isShowing()) {
  
          try {
  
              pDialog.dismiss();
  
          } catch (Exception e) {
  
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>}</p>