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 CatLog 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 suff under a single it works, but the Ad is on top, messing up with the tab under it. How can I solve it?
--
---
You received this message because you are subscribed to the Google Groups "Google AdMob Ads Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I think as you are mixing the Java Code and XML implementation, this is the reason for an error without getting the required result.Because as far as the lookup, you are not looking up the AdView in the Java code. Rather you are looking up for the layout containing the AdView and you are adding the AdView again.What you can do to set Ad at the bottom is use only the XML implementation part. And that works for me.I can point you to the implementation here. You can see the code by clicking here "Create your banner in XML"Best,Kunal
11-27 20:30:32.777: E/AndroidRuntime(4681): FATAL EXCEPTION: main11-27 20:30:32.777: E/AndroidRuntime(4681): java.lang.RuntimeException: Unable to resume activity {com.pipodi.lolservicestatuseuwonly/com.pipodi.lolservicestatuseuwonly.MainActivity}: java.lang.NullPointerException11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread.performResumeActivity(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread.handleResumeActivity(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread.access$600(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread$H.handleMessage(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.os.Handler.dispatchMessage(Handler.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.os.Looper.loop(Looper.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.ActivityThread.main(ActivityThread.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at java.lang.reflect.Method.invokeNative(Native Method)11-27 20:30:32.777: E/AndroidRuntime(4681): at java.lang.reflect.Method.invoke(Method.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at dalvik.system.NativeStart.main(Native Method)11-27 20:30:32.777: E/AndroidRuntime(4681): Caused by: java.lang.NullPointerException11-27 20:30:32.777: E/AndroidRuntime(4681): at com.pipodi.lolservicestatuseuwonly.MainActivity.onResume(MainActivity.java:66)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.Instrumentation.callActivityOnResume(Instrumentation.java)11-27 20:30:32.777: E/AndroidRuntime(4681): at android.app.Activity.performResume(Activity.java)11-27 20:30:32.777: E/AndroidRuntime(4681): ... 13 more11-27 20:30:32.802: E/GooglePlayServicesUtil(4681): The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
--