Bata Kos
Bata Kos

Reputation: 85

Banner ad error: The ad size and ad unit ID must be set before loadAd is called

It is not a duplicate question. I already tried solutions from similiar questions but none of them worked.

My Google Ad Banner code is below:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/konstraitLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:padding="0dp"
app:layoutDescription="@xml/activity_main_scene"
tools:context=".MainActivity">

    ...

    <com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="Banner"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

    ...

</androidx.constraintlayout.widget.ConstraintLayout>

The code in MainActivity:

adView = findViewById(R.id.adView);

AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);

So I added my banner in XML. I found it in java and then called it, but I guess I am missing something since I've got the following error:

The ad size and ad unit ID must be set before loadAd is called

Thanks for answer.

Upvotes: 0

Views: 92

Answers (1)

sweak
sweak

Reputation: 1970

The adSize tag should have its value passed in capital letters. Replace this:

ads:adSize="Banner"

with this:

ads:adSize="BANNER"

Upvotes: 1

Related Questions