I have followed a few tutorials / stackoverflow threads to learn how to add an Admob banner to the bottom of my UI.
I have added the adMob sdk to the lib, added the following to the XML for the UI that I want to show the ad on
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000">
<com.google.ads.AdView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/adMob"
android:layout_alignParentBottom="true"
ads:adUnitId="YOUR AdMob publisher ID"
ads:adSize="BANNER"/>
I then add the following to my java code for this UI
AdView adview = (AdView)findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(true);
adview.loadAd(re);
The problem I have is that I have no xml called "adView". I’ve tried a few different versions of the Java code (each tutorial is a bit different) but all result in a similar java error. What am I missing?
You haven’t got any
R.id.adView(at least in the code you paste), you have to useR.id.adMob, because this is the view’s ID.You have to add this to your Layout file: