Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New admob Express Native ads fail with IllegalStateException

I've been trying to integrate express native ads to my application. In the express native ads documentation I've read that they work best when displayed with FULL_WIDTH ad size. I tried to set my ad size to FULL_WIDTH but it fails with IllegalStateException:

Caused by: java.lang.IllegalStateException: The ad size and ad unit ID must be set before loadAd is called.

Here is my xml code:

<com.google.android.gms.ads.NativeExpressAdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="FULL_WIDTH"
ads:adUnitId="@string/native_ad_unit"/>

The ad unit is correct, it works with other ad sizes like 320x150 etc.

Is there something wrong with my implementation?

Cheers

like image 260
John Smith Avatar asked May 20 '16 21:05

John Smith


2 Answers

I found a solution, it will work if you use it like this:

<com.google.android.gms.ads.NativeExpressAdView
 android:id="@+id/adView"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 ads:adSize="FULL_WIDTHx80"
 ads:adUnitId="@string/native_ad_unit"/>
like image 62
John Smith Avatar answered Oct 18 '22 03:10

John Smith


You can only set it programmatically. Here is an excerpt from the documentation:

Publishers can also use the FULL_WIDTH constant when programmatically creating an AdSize for a NativeExpressAdView. In this case, the ad will occupy the entire width of the device screen.

Source: https://firebase.google.com/docs/admob/android/native-express#nativeexpressadview

like image 45
Ankit Batra Avatar answered Oct 18 '22 02:10

Ankit Batra