Rajubhai Rathod
Rajubhai Rathod

Reputation: 511

Admob Native Express Ads

I am trying to Integrate Native Express in one of my quote application. I have followed Google guide for same but still facing issue for integrate Admob Native Express banner in my application. Its getting crashed. I have attached LogCat as well my java and xml code for same. Please check and let me know that what is I am missing. Thanks

My LogCat

06-27 19:52:12.921: E/AndroidRuntime(32196): FATAL EXCEPTION: main
06-27 19:52:12.921: E/AndroidRuntime(32196): Process: com.vmapps.quotesking, PID: 32196
06-27 19:52:12.921: E/AndroidRuntime(32196): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vmapps.quotesking/com.vmapps.quotesking.material.QuoteViewActivity}: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2699)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2773)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread.access$900(ActivityThread.java:177)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1434)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.os.Handler.dispatchMessage(Handler.java:102)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.os.Looper.loop(Looper.java:135)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread.main(ActivityThread.java:5930)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at java.lang.reflect.Method.invoke(Native Method)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at java.lang.reflect.Method.invoke(Method.java:372)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)
06-27 19:52:12.921: E/AndroidRuntime(32196): Caused by: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.google.android.gms.ads.internal.client.zzab.zzdg(Unknown Source)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.google.android.gms.ads.internal.client.zzab.zza(Unknown Source)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.google.android.gms.ads.BaseAdView.loadAd(Unknown Source)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.google.android.gms.ads.NativeExpressAdView.loadAd(Unknown Source)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at com.vmapps.quotesking.material.QuoteViewActivity.onCreate(QuoteViewActivity.java:209)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.Activity.performCreate(Activity.java:6178)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
06-27 19:52:12.921: E/AndroidRuntime(32196):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2652)
06-27 19:52:12.921: E/AndroidRuntime(32196):    ... 10 more

My Java Code

NativeExpressAdView adView = (NativeExpressAdView)findViewById(R.id.adView);

    AdRequest request = new AdRequest.Builder()
        .addTestDevice("YOUR_DEVICE_ID")
        .build();
    adView.loadAd(request);

My XML for same is below

<com.google.android.gms.ads.NativeExpressAdView
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
     ads:adSize="320x80">
</com.google.android.gms.ads.NativeExpressAdView>

Thanks

Upvotes: 1

Views: 568

Answers (1)

P1x
P1x

Reputation: 1488

It seems that the namespace prefix declaration for ads is wrong

Try replacing

xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"

with

 xmlns:ads="http://schemas.android.com/apk/res-auto"

Upvotes: 2

Related Questions