Trey Balut
Trey Balut

Reputation: 1395

Set my AdMob UnitId programmaticallyu

I'm trying to set my AdMObUnitId in the program.

Here is and XML snip of the layout.

  <com.google.ads.AdView
     android:id="@+id/AdView01"
     android:layout_width="fill_parent"
     android:layout_height="60dp"
     android:layout_marginTop="0dp"
     android:gravity="center" >

    </com.google.ads.AdView>

And here is the code:

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;


  testStr="ca-app-pub-xxxxxxxxxxxxxxx";

   AdView mAdView = (AdView) findViewById(R.id.AdView05);

   mAdView.setAdUnitId(testStr);

   AdRequest adRequest = new AdRequest();

   mAdView.loadAd(adRequest);

I'm getting the following error: " The method setAdUnitId(String) is undefined for the type AdView "

How do I fix the error or what is the correct way to change the AdUnitIt in the program.

TIA

Upvotes: 0

Views: 59

Answers (1)

nKn
nKn

Reputation: 13761

Seems like you haven't included the correct libraries in your project.

You have:

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

It should be:

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

Upvotes: 1

Related Questions