Dedicated Server

How to fix some common errors during admob implementation ?

This tutorial is basically a walkthrough of some common admob errors. You might have come across these issues at least once during admob sdk integration.

Error 1 : There was a problem getting an ad response. ErrorCode: 0, Failed to load ad: 0

error code name : ERROR_CODE_INTERNAL_ERROR
error defenition : Something happened internally; for instance, an invalid response was received from the ad server.

Case 1 : Suppose you have recently created an ad unit and test ads are working fine, but immediately after that when you switch to live ads the ads stopped showing with the error log "failed to load ad:0". If this is the case, there is nothing to worry. This is because Admob takes sometime to setup your live ads and it will be ready only a few hours after the ad unit was created. Basically if its fetching the test ads successfully, your implementation is correct.

Case 2 : Missing to fill out payment details can be another reason for this error message. When you login to your admob dashboard if you find a notice saying something like ads wont work until payment details are added, then fill out the payment details and see if ads are working fine.

Error 2 : There was a problem getting an ad response. ErrorCode: 1,Failed to load ad: 1

error code name : ERROR_CODE_INVALID_REQUEST
error defenition : The ad request was invalid; for instance, the ad unit ID was incorrect.

This error is thrown usually when you have provided incorrect values of app id or ad unit id. Mixing these values with each other is a usual mistake.

Double check you have used correct values for ad unit id, app id. The app id is the one with a "~" somewhere in between and the ad unit id is the one with a "/". The app id(one with "~") should be passed while you initialise the ads sdk like this

MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");

and the ad unit id should be specified as an attribute to the ad unit, for example if you ad it from layout it should be like this

<com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">

and can be specified programmatically like this

AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");

Error 3 : There was a problem getting an ad response. ErrorCode: 2,Failed to load ad: 2

error code name : ERROR_CODE_NETWORK_ERROR
error defenition : The ad request was unsuccessful due to network connectivity.
  • This error usually happens when you have a weak/no internet connection at all. Double check you have proper internet connection. 
  • This error can also be thrown because of an incorrect date setting on your phone. Setting it properly can get rid of the issue.
Error 4 : There was a problem getting an ad response. ErrorCode: 3,Failed to load ad: 3

error code name : ERROR_CODE_NO_FILL
error defenition : The ad request was successful, but no ad was returned due to lack of ad inventory.

As the error definition says, our ad request is successful but there is lack of ads to be served to our particular ad unit. One reason for this error could be that you might have blocked too many ads for this unit from the admob dashboard. This could also mean that there are no ads are available to be served at the moment and it may start serving the ads later when more ads are available in the inventory



2 comments:

  1. i am facing a problem in which ad is not showing and the error is ad wasn't ready yet.

    ReplyDelete