Failed to load ad (Error 1)

15,248

Solution 1

I got this error on Adaptive banner for android

I/Ads: Ad failed to load : 1

because of this line

width = (int)( metrics.widthPixels);

Solution

DisplayMetrics metrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(metrics);

width = (int)( metrics.widthPixels/metrics.density);

AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mContext, width);

I hope it helps someone.

Solution 2

Error 1 means the ID is wrong.

Admob gives you a number like this and is the general ID, with ~ :

ca-app-pub-9611919736642270~3440171884

And the ads id with / is to the request;

ca-app-pub-9611919736642270/3440171834

Solution 3

The error code 1 refers to Invalid request.

//(public static final int ERROR_CODE_INVALID_REQUEST The ad request was invalid; for instance, the ad unit ID was incorrect. Constant Value: 1) //

Thus you must check whether your Ad-Ids are defined at right place. Don't put banner ads id to interestial ads and vice versa. for other error codes just take a look on this link: https://developers.google.com/android/reference/com/google/android/gms/ads/AdRequest#ERROR_CODE_NO_FILL

Share:
15,248
Admin
Author by

Admin

Updated on July 07, 2022

Comments

  • Admin
    Admin almost 2 years

    Have been searching for hours on google, but still without success. I always get the Error Message and the adBanner doesnt load:

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

    build.gradle

    compile 'com.android.support:appcompat-v7:24.0.0'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    

    Android Manifest

    <activity
            android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent"
            />
    

    layout

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        android:layout_marginTop="20dip"
        ads:adUnitId="pub-*****************"
        android:layout_below="@+id/middle"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />
    

    activity (imports)

    import com.google.android.gms.ads.AdRequest;
    import com.google.android.gms.ads.AdView;
    

    activity

    AdView adView = (AdView)findViewById(R.id.adView);
    
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
    

    permissions are also added

    ty for your help in advance

  • Will Calderwood
    Will Calderwood about 4 years
    Thanks. I assumed the width passed should be the width in pixels, but it's not. It's widthPixels / density.
  • Anbarasu Chinna
    Anbarasu Chinna almost 4 years
    can you explain clearly? I have adUnitId with ~ I can not load add in both debug and release build. How do I fix this.
  • Leonid Ustenko
    Leonid Ustenko almost 4 years
    Thanks. Exactly my case