Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 广告请求成功,但由于缺少广告库存,没有返回广告_Android_Admob - Fatal编程技术网

Android 广告请求成功,但由于缺少广告库存,没有返回广告

Android 广告请求成功,但由于缺少广告库存,没有返回广告,android,admob,Android,Admob,我是AdMob的新手。首先,我尝试创建一个带有不同类型广告的测试应用程序。 我使用真实的ad_unit_id和nexus 4进行测试 我对所有活动使用1个布局xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk

我是AdMob的新手。首先,我尝试创建一个带有不同类型广告的测试应用程序。 我使用真实的ad_unit_id和nexus 4进行测试

我对所有活动使用1个布局xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/empty_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
</LinearLayout>
当我尝试使用全屏广告创建活动时,出现错误消息:

Ad request successful, but no ad returned due to lack of ad inventory.
活动代码:

public class AdBannerActivity extends Activity {

    private AdView adView;

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

        adView = new AdView(this, AdSize.SMART_BANNER, getString(R.string.adUnitId));
        adView.setAdListener(this);

        LinearLayout layout = (LinearLayout) findViewById(R.id.empty_layout);

        layout.addView(adView);

        adView.loadAd(new AdRequest());
    }

    @Override
    public void onDestroy() {
        if (adView != null) {
            adView.destroy();
        }
        super.onDestroy();
    }
}
public class AdInterstitialActivity extends Activity implements AdListener {

    private InterstitialAd interstitial;

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

        interstitial = new InterstitialAd(this, getString(R.string.adUnitId));

        interstitial.setAdListener(this);

        AdRequest adRequest = new AdRequest();

        interstitial.loadAd(adRequest);
    }

    @Override
    public void onReceiveAd(Ad ad) {
        if (ad == interstitial) {
            interstitial.show();
        }
    }

    @Override
    public void onDismissScreen(Ad ad) {
    }

    @Override
    public void onFailedToReceiveAd(Ad ad, ErrorCode error) {
        Log.e("AdTest", "Error code: " + error);
    }

    @Override
    public void onLeaveApplication(Ad ad) {
    }

    @Override
    public void onPresentScreen(Ad ad) {
    }
}
我做错了什么? 如何解决这个问题


解决方案:为AdMob帐户中的间隙广告创建新的广告单元id。

如果您有此错误,则您的代码是正确的。Admob没有为你的应用程序显示任何广告(你的国家、你的广告类型是决定因素)

如果您想在测试模式下测试广告的行为,请查看以下链接:

编辑:如果您刚刚创建了Admob帐户,则可能需要一些时间和请求才能发送第一个广告。 我在某个地方看到,人们在使用自定义大小作为横幅时也会出现此错误,因此请务必检查:


测试模式工作正常,但我需要在此测试应用程序中显示真实的广告。@Drafff,请等待1-2天,将显示真实的AdMob横幅。这是我的情况下的解决方案。