Error is occurring in my interstitial ad code for AdMob when i am using my own ad unit id

Viewed 3342

I am new to AdMob i added app name and platform in admob account.In this app i have added unit ad of interstitial ad.And created its ad unit id.

Now in android studio i have wrote simple code as per the instructions from AdMob. So when button gets clicked it shows ad perfectly when i use the testing ad unit id but when i use my own created id its not getting load and the logcat shows as follows:

07-04 23:47:25.165 17901-17914/h.safmical.kk W/Ads: There was a problem getting an ad response. ErrorCode: 0
07-04 23:47:25.169 17901-17901/h.safmical.kk W/Ads: Failed to load ad: 0
07-04 23:47:25.169 17901-17901/h.safmical.kk I/Ads: onAdFailedToLoad
07-04 23:47:33.028 17901-17901/h.safmical.kk D/TAG: The interstitial wasn't loaded yet.
07-04 23:50:57.947 17901-18143/h.safmical.kk E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb9aabcf0

My mainactivity:

MainActivity.java:

package h.safmical.kk;

import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class MainActivity extends Activity {
    private InterstitialAd mInterstitialAd;

    Button click;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("*************************");
        mInterstitialAd.loadAd(new AdRequest.Builder().build());

        click = (Button) findViewById(R.id.click);
        click.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                } else {
                    Log.d("TAG", "The interstitial wasn't loaded yet.");
                }
            }
        });

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
               Log.i("Ads", "onAdLoaded");
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
              Log.i("Ads", "onAdFailedToLoad");
            }

            @Override
            public void onAdOpened() {
            Log.i("Ads", "onAdOpened");
            }

            @Override
            public void onAdLeftApplication() {
            Log.i("Ads", "onAdLeftApplication");
            }

            @Override
            public void onAdClosed() {
              mInterstitialAd.loadAd(new AdRequest.Builder().build());
            }
        });
    }
}

My Gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "h.safmical.kk"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.google.android.gms:play-services-ads:10.2.4'
    testCompile 'junit:junit:4.12'
}

Please help me to solve this.

2 Answers
Related