MasterSinge
MasterSinge

Reputation: 675

Admob Error : Failed to load ad

I run my app with android studio, but my add doesn't appear... Every time I run my app no ads appear and I get this error message in Logcat:

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

Here is my MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    MobileAds.initialize(MainActivity.this, "ca-app-pub-4760206671218452~8890405785");


    mAdview =  findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
    mAdview.loadAd(adRequest);


    mAdview.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            Toast.makeText(getApplicationContext(),"RKAd Loaded",Toast.LENGTH_SHORT).show();
            // Code to be executed when an ad finishes loading.
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Toast.makeText(getApplicationContext(),"Ad Failed to load",Toast.LENGTH_SHORT).show();
            // Code to be executed when an ad request fails.
        }

        @Override
        public void onAdOpened() {
            Toast.makeText(getApplicationContext(),"Ad Opened",Toast.LENGTH_SHORT).show();
            // Code to be executed when an ad opens an overlay that
            // covers the screen.
        }

        @Override
        public void onAdLeftApplication() {
            Toast.makeText(getApplicationContext(),"Ad Left Application",Toast.LENGTH_SHORT).show();
            // Code to be executed when the user has left the app.
        }

        @Override
        public void onAdClosed() {
            Toast.makeText(getApplicationContext(),"RKAd Closed",Toast.LENGTH_SHORT).show();
            // Code to be executed when when the user is about to return
            // to the app after tapping on an ad.
        }
    });

Here my activity_main.xml

 <com.google.android.gms.ads.AdView
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="https://schemas.android.com/tools"
            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="SMART_BANNER"
            android:layout_gravity="bottom"
            ads:adUnitId="ca-app-pub-4760206671218452/1505195192">

        </com.google.android.gms.ads.AdView>

I have on the screen Ad Failed to load. I created my Admob account yesterday, but the ad doesn't display :(

Upvotes: 0

Views: 5734

Answers (2)

Pablo
Pablo

Reputation: 104

i use this for testing an ad

AdView adView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
        .setRequestAgent("android_studio:ad_template").build();
adView.loadAd(adRequest);

and in the ads xml (banner test id)

ads:adUnitId="ca-app-pub-3940256099942544/6300978111"

if you want to test your own ad you have to change the id and the tag on setRequestAgent

.setRequestAgent("myapp").build();

Upvotes: 0

Sheikh Hasib
Sheikh Hasib

Reputation: 7503

1. If your account is new please wait 2-3 Hours, it will automatically start showing ads.

About this issue google say:

"It could be that you have only recently created a new Ad Unit ID and requesting for live ads. It could take a few hours for ads to start getting served if that is that case. If you are receiving test ads then your implementation is fine. Just wait a few hours and see if you are able to receive live ads then. If not, can send us your Ad Unit ID for us to look into."

So you have to wait for a few hours.

Check Out Referance

2. After that if still does not started showing ads, probably you forgot to setup payment settings. So You have to complete that.

Upvotes: 2

Related Questions