New admob Express Native declarations with IllegalStateException error

I tried to integrate express ads into my application. In the express documentation for my own ads, I read that they work best when displayed with an ad size of FULL_WIDTH. I tried to set my ad size to FULL_WIDTH, but it does not work 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, such as 320x150, etc.

Is there something wrong with my implementation?

Greetings

+6
source share
2 answers

I found a solution, it will work if you use it as follows:

 <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"/> 
+19
source

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

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

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

+1
source

All Articles