简体   繁体   English

无法加载原生广告:0错误

[英]Failed to load Native ad: 0 Error

I am implementing code for native ads that is given by google. 我正在为Google提供的原生广告实现代码。 That is working okay with google google可以正常工作

ad unit id ADMOB_AD_UNIT_ID = "ca-app-pub-3940256099942544/2247696110" 广告单元ID ADMOB_AD_UNIT_ID =“ ca-app-pub-3940256099942544 / 2247696110”

But when I replace with my id its not showing ad and execute onAdFailedToLoad method and got Failed to load native ad: 0 error . 但是,当我用自己的ID替换它时,它不显示广告,并执行onAdFailedToLoad方法并无法加载本地广告:0 error

I tried two different ad unit id but it didn't load ad.

so what should I do??please help me 

I tried below code 我尝试下面的代码

final LayoutInflater li = (LayoutInflater) appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            AdLoader.Builder builder = new AdLoader.Builder(appContext, Global.ADMOB_AD_UNIT_ID);

            builder.forContentAd(new NativeContentAd.OnContentAdLoadedListener() {
                @Override
                public void onContentAdLoaded(NativeContentAd ad) {
                    //viewHolder.rlnativead.setVisibility(View.VISIBLE);
                    NativeContentAdView adView = (NativeContentAdView)li
                            .inflate(R.layout.ad_content, null);
                    populateContentAdView(ad, adView);
                    viewHolder.fl_adplaceholder.removeAllViews();
                    viewHolder.fl_adplaceholder.addView(adView);
                }
            });

            AdLoader adLoader = builder.withAdListener(new AdListener() {
                @Override
                public void onAdFailedToLoad(int errorCode) {
//                  Toast.makeText(appContext, "Failed to load native ad: "
//                          + errorCode, Toast.LENGTH_SHORT).show();
                    Log.e("Call List adapter","Failed to load native ad: "+errorCode);
                }
            }).build();

            adLoader.loadAd(new AdRequest.Builder().build());

请添加至少一台测试设备,然后尝试一下,它可能会对您有所帮助,

AdRequest adRequest = new AdRequest.Builder() .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID") .build();

this could be lately answered but expecting to help for others having similiar problem.One of the major cause for this is incorrect dimension 这可以在最近得到解答,但希望对其他有类似问题的人有所帮助。主要原因之一是尺寸不正确

In my case before it was 以我为例

 <?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.NativeExpressAdView android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="@string/native_ad_id"
    ads:adSize="320x250"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto">
</com.google.android.gms.ads.NativeExpressAdView>

I was making the mistake in giving the adSize ,so i just changed the add size with the below dimension and got fixed. 我在给adSize时犯了一个错误,所以我只是用下面的尺寸更改了添加尺寸并得到了解决。 Thanks. 谢谢。

 ads:adSize="320x250"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM