John Smith
John Smith

Reputation: 874

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

Upvotes: 6

Views: 6861

Answers (2)

John Smith
John Smith

Reputation: 874

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"/>

Upvotes: 19

Ankit Batra
Ankit Batra

Reputation: 863

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

Upvotes: 1

Related Questions