Admob Interstitial ad showing Error building request URL

Viewed 6351

I have implemented admob interstitial ad recently and getting exception/error as Error building request URL. from method onAdFailedToLoad(), and also my ad is not shown .

My code:

InterstitialAd interstitialAd;
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
        
                InterstitialAd interstitialAd = new InterstitialAd(MainActivity.this);
                interstitialAd.setAdUnitId(KEY);
                MobileAds.initialize(MainActivity.this, new OnInitializationCompleteListener() {
                    @Override
                    public void onInitializationComplete(InitializationStatus initializationStatus) {
                        Log.e("app","MobileAds onInitializationComplete");
                    }
                });
                interstitialAd.loadAd(new AdRequest.Builder().build());
                interstitialAd.setAdListener(new AdListener(){
                    @Override
                    public void onAdLoaded() {
                        Log.e("app","ad loaded");
                    }
        
                    @Override
                    public void onAdFailedToLoad(LoadAdError loadAdError) {
                        Log.e("app","ad failedToLoad: "+loadAdError.getMessage()); //error/exception here
                    }
                });
}
                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        if(interstitialAd.isLoaded()) {
                    interstitialAd.show();
                    Log.e("app","ad loaded");
                }
                else Log.e("app","ad not loaded yet");              
    }
}

I have registered my id properly in the Manifest.xml

<application>
<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="@string/KEY"/>
    </application>

Followed same guideline shown in here

5 Answers

Make sure you use the correct test ad ID from AdMob in the call InterstitialAd. This is not the same as your App ID, it has an attached slash and a number behind it.

For testing, use ca-app-pub-3940256099942544/1033173712 which is the test ID given by the docs at the time of writing.

I've noticed that this error occurs in these cases:

  • When you type wrong adUnitId.
  • When you pass wrong AdSize (ex. too big or too small).
  • When Google stops displaying ads in your app, because you break some admob rules.

I had a similar problem, after checking I found out that I entered the unit ID incorrectly.

For instersticial Ad the Sample ad unit ID must be: ca-app-pub-3940256099942544/1033173712

Here is the demo ad units that point to specific test creatives for each format.

enter image description here

Never use App id from the console to Test ads in your app. Instead use these sample id's:

Ad format Sample Ad Unit Id How it looks
App Open ca-app-pub-3940256099942544/3419835294
Banner ca-app-pub-3940256099942544/6300978111
Interstitial ca-app-pub-3940256099942544/1033173712 No preview
Interstitial Video ca-app-pub-3940256099942544/8691691433

And a lot more. You can find all of them here

Related