Search code examples
androidxmlandroid-studioadview

Android Studio AdView XML tag empty body?


For some reason, my Banner Ad is highlighted in my main activity xml file with the "tip": XML tag has empty body Reports empty tag body. The validation works in XML / JSP / JSPX / HTML /XHTML file types.

<com.google.android.gms.ads.AdView
        android:id="@+id/bannerAd"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@+id/banner_ad_unit_id"></com.google.android.gms.ads.AdView>

I have never been able to display ads or even test ads in my app, but always kept this Adview just in case it decided to work one day. After updating Android Studio, this is the first time I saw this appear over the AdView.


Solution

  • That's just an advice from Android Studio, not an error.

    Just change your code to:

    <com.google.android.gms.ads.AdView
            android:id="@+id/bannerAd"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            ads:adSize="BANNER"
            ads:adUnitId="@+id/banner_ad_unit_id"/>
    

    You can also press Alt+Enter (or Option+Enter on macOS) to see the suggested auto-edit.