I'm trying to set an AdMob Banner for my app. In my first Activity I've got a ListView, so I need to put the Banner on the bottom of it. I've searched for something on the internet, and I've found something but, unfortunately, it doesn't work for me.
I tried to edit the XML file of the main Activity layout, like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/main_list"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<com.google.android.gms.ads
android:layout_alignParentBottom="true">
</com.google.android.gms.ads>
</RelativeLayout>
But the LogCat says:
> 11-27 01:36:21.783: E/AndroidRuntime(19734): FATAL EXCEPTION: main
>11-27 01:36:21.783: E/AndroidRuntime(19734): java.lang.RuntimeException: Unable to start >activity ComponentInfo{com.pipodi.lolservicestatuseuwonly/com.pipodi.lolservicestatuseuwonly.MainActivity}: android.view.InflateException: Binary XML file line #25: Error inflating class com.google.ads.AdView
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.ActivityThread.access$600(ActivityThread.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.os.Handler.dispatchMessage(Handler.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.os.Looper.loop(Looper.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.ActivityThread.main(ActivityThread.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at java.lang.reflect.Method.invokeNative(Native Method)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at java.lang.reflect.Method.invoke(Method.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at dalvik.system.NativeStart.main(Native Method)
>11-27 01:36:21.783: E/AndroidRuntime(19734): Caused by: android.view.InflateException: Binary XML file line #25: Error inflating class com.google.ads.AdView
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.rInflate(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.inflate(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.inflate(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.inflate(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.Activity.setContentView(Activity.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at com.pipodi.lolservicestatuseuwonly.MainActivity.onCreate(MainActivity.java:43)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.Activity.performCreate(Activity.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): ... 12 more
>11-27 01:36:21.783: E/AndroidRuntime(19734): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.pipodi.lolservicestatuseuwonly-1.apk
>11-27 01:36:21.783: E/AndroidRuntime(19734): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at java.lang.ClassLoader.loadClass(ClassLoader.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at java.lang.ClassLoader.loadClass(ClassLoader.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): at android.view.LayoutInflater.createView(LayoutInflater.java)
>11-27 01:36:21.783: E/AndroidRuntime(19734): ... 22 more
This is the method OnCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_main);
// Create the adView.
adView = new AdView(this);
adView.setAdUnitId("ca-app-pub-9509002681827594/8300786666");
adView.setAdSize(AdSize.BANNER);
LinearLayout layout = (LinearLayout)findViewById(R.id.main);
// Add the adView to it.
layout.addView(adView);
// Initiate a generic request.
AdRequest adRequest = new AdRequest.Builder().build();
// Load the adView with the ad request.
adView.loadAd(adRequest);
super.onCreate(savedInstanceState);
c=this.getApplicationContext();
list = (ListView)this.findViewById(R.id.main_list);
ParsingPaginaWeb parsing = new ParsingPaginaWeb();
parsing.execute("");
}
And the last, the Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.pipodi.lolservicestatuseuwonly"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
<activity
android:name="com.pipodi.lolservicestatuseuwonly.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.pipodi.lolservicestatuseuwonly.PostCatcher"
android:label="@string/title_activity_post_catcher"
android:parentActivityName="com.pipodi.lolservicestatuseuwonly.MainActivity">
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>
</manifest>
If I edit the XML, putting all the stuff under a single LinearLayout it works, but the Ad is on top, messing up with the tab under it. How can I solve it?
Thanks guys!