0

I was having difficulty adding admob ads into an android app and was continually receiving the error message: There was a problem getting an ad response. ErrorCode: 0 followed by Failed to load ad: 0., so I copied the code directly from the tutorial and am still getting the same errors. I am using everything as provided by android studio in this tutorial: https://developers.google.com/admob/android/quick-start

Here is the xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="michaelsinn.contact.gmail.com.testads.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
    <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="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

</android.support.constraint.ConstraintLayout>

And Activity:

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity {
    private AdView mAdView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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

        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("[Correct test device id is here]").build();
        mAdView.loadAd(adRequest);
    }
}

Any and all help is appreciated! Thank you

  • Possible duplicate of [admob getting an ad response. ErrorCode: 0 Failed to load ad:0](https://stackoverflow.com/questions/31972862/admob-getting-an-ad-response-errorcode-0-failed-to-load-ad0) – Evan Weissburg Jan 13 '18 at 05:05
  • Yeah I looked there before but I couldnt find anything to help – Michael Sinn Jan 13 '18 at 15:43

2 Answers2

0

try this instead.

AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
mAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
Toast.makeText(getApplicationContext(),"Ad 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(),"Ad 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.
    }
});
0

Your code is fine

try running the app on emulator and see the result

another thing

go to admob

settings

test deices

ADD TEST DEVICE

and then go with the instruction to add your own device as a test device

if the ad worked fine with the test ad banner then you are okay

if not then check your mainfest

and make sure you added

<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxx~xxxxx" />
Ahmed
  • 1
  • 4