6

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

John Smith
  • 788
  • 6
  • 24

2 Answers2

19

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"/>
John Smith
  • 788
  • 6
  • 24
  • Thank you very much, you save me a lot of time, the adSize was the problem. – Marta Rodriguez Jul 18 '16 at 16:51
  • Hi, I am using Native ad and its showing Internal Error. it's been two days and nothing worked for me. My xml tag – chetan Nov 17 '16 at 08:13
  • NOTE: `ads:adSize="FULL_WIDTHxsome_height"` won't work if `NativeExpressAdView` has any Horizontal margins. Because it tries to occupy entire width of device. – Chintan Shah Feb 08 '17 at 07:43
1

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

Ankit Batra
  • 669
  • 8
  • 12
  • NativeExpressAdView adView = (NativeExpressAdView) v.findViewById(R.id.adView); adView.setAdSize(AdSize.FULL_WIDTH); this isn't working... – Janine Kroser May 23 '16 at 10:00
  • You will be able to set AdSize only if you are creating the NativeExpressAdView programmatically. I was able to find an example [here](https://firebase.google.com/docs/reference/android/com/google/android/gms/ads/NativeExpressAdView). Just use FULL_WIDTH instead of the 400 width as given in the example. – Ankit Batra May 23 '16 at 10:26