title: Android - Google Play Service throw IllegalStateException complaining about size and ad unit id
body: <p>Since I replaced the Admob library for the Google Play Service library, my Android app sometimes triggers the following exception</p>
  
  <pre><code>java.lang.RuntimeException: Unable to start activity ComponentInfo{com.XXX.XXX/com.XXX.XXX.ui.activity.FeedActivity}: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2328)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2386)
  at android.app.ActivityThread.access$900(ActivityThread.java:169)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1277)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5476)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
  at com.google.android.gms.internal.ak.an(Unknown Source)
  at com.google.android.gms.internal.ak.a(Unknown Source)
  at com.google.android.gms.ads.AdView.loadAd(Unknown Source)
  at com.XXX.newslibrary.ui.activity.FeedActivity.initActivityLayout(FeedActivity.java:255)
  at com.XXX.newslibrary.ui.activity.FeedActivity.onCreate(FeedActivity.java:72)
  at android.app.Activity.performCreate(Activity.java:5451)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
  ... 11 more
  </code></pre>
  
  <p>Basically the exception is complaining that I'm not setting the ad size and unit id before loadAd. This is me code:</p>
  
  <pre><code>    mAdView = new AdView(this);
      mAdView.setAdSize(AdSize.BANNER);
      mAdView.setAdUnitId(SourceActivity.APPLICATION_ADMOB_BANNER_ID);
  
      LinearLayout layout = (LinearLayout) findViewById(R.id.activity_view);
      layout.addView(mAdView);
  
      AdRequest adRequest = new AdRequest.Builder().build();
      mAdView.loadAd(adRequest);
      mAdView.setVisibility(View.GONE);
  
      mAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Log.d(TAG, "onAdLoaded");
            mAdView.setVisibility(View.VISIBLE);
        }
      });
  </code></pre>
  
  <p>As you can see, everything is correct. And as I said before the exception doesn't appear always in fact it only appeared a few times.</p>
  
  <p>Does anyone have an idea of what might be causing this?</p>