简体   繁体   中英

Error inflating class com.google.ads.Adview Android

I'm rather new to coding (I have a few apps on the market, but no games yet) I therefore decided to create a game. I made the whole game and it worked, but when I attempted to integrate Google AdMob, it all went wrong.

Here is my main.xml (the place I want the ads)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"
android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" android:background="@drawable/main_bg">

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:src="@drawable/main_title" />
<TextView
    android:id="@+id/wwwtext"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:textColor="@color/unsel"
    android:textColorHighlight="@color/sel" android:layout_marginBottom="35dp"/>
<RelativeLayout
    android:id="@+id/btn_start"
    android:layout_width="450px"
    android:layout_height="150px"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" >


    <ImageView
        android:id="@+id/ing_btn"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/btn" />



    <TextView
        android:id="@+id/text_start"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:gravity="center_horizontal"
        android:text="@string/start_game"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <com.google.ads.Adview android:id= "@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId= "a153123c67abc55"
        ads:adSize= "BANNER"
        ads:loadAdOnCreate= "true"/>

</RelativeLayout>

This is my manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.benchaful.Invasion"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="19" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" 
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
    >
    <activity
        android:name=".MainMenu"
        android:label="@string/app_name" android:screenOrientation="sensorLandscape">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="Game" android:screenOrientation="sensorLandscape">
    </activity>
   <activity android:name= "com.google.ads.AdActivity"
        android:configChanges=     "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
   </application>

    <uses-permission android:name= "android.permission.INTERNET"/>
</manifest>

And this is my LogCat

03-07 08:02:53.229: E/AndroidRuntime(6633): FATAL EXCEPTION: main
03-07 08:02:53.229: E/AndroidRuntime(6633): java.lang.RuntimeException: Unable to start     activity ComponentInfo{com.benchaful.Invasion/com.benchaful.Invasion.MainMenu}: android.view.InflateException: Binary XML file line #54: Error inflating class com.google.ads.Adview
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2121)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2146)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread.access$700(ActivityThread.java:140)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1238)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.os.Looper.loop(Looper.java:137)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread.main(ActivityThread.java:4944)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at  java.lang.reflect.Method.invokeNative(Native Method)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at java.lang.reflect.Method.invoke(Method.java:511)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at dalvik.system.NativeStart.main(Native Method)
03-07 08:02:53.229: E/AndroidRuntime(6633): Caused by: android.view.InflateException: Binary XML file line #54: Error inflating class com.google.ads.Adview
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:752)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:760)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.inflate(LayoutInflater.java:495)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:318)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.Activity.setContentView(Activity.java:1924)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at com.benchaful.Invasion.MainMenu.onCreate(MainMenu.java:31)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.Activity.performCreate(Activity.java:5188)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at     android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2085)
03-07 08:02:53.229: E/AndroidRuntime(6633):     ... 11 more
03-07 08:02:53.229: E/AndroidRuntime(6633): Caused by: java.lang.ClassNotFoundException: com.google.ads.Adview
03-07 08:02:53.229: E/AndroidRuntime(6633):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.createView(LayoutInflater.java:558)
03-07 08:02:53.229: E/AndroidRuntime(6633):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:693)
03-07 08:02:53.229: E/AndroidRuntime(6633):     ... 22 more

I would be very grateful if anyone could tell me what has gone wrong and how to solve it.

Thank-you

The staktrace clearly says that it cannot find com.google.ads.Adview.

You need to add the library containing that class to your APK. That is either Google Play Services or Google Admob SDK-6.4.1 depending on which you are using to integrate with Admob.

Sounds like the first thing you need to do is import the google-play-services-lib into Eclipse (your comment makes it sound like you are using Eclipse). Go to File -> Import -> Android -> Existing Android Code Into Workspace. Browse to the Google Play Services Library in your SDK directory. By default it is usually under C:/Users/[username]/AppData/Local/Android/extras/google/google_play_services/libproject . Select the google-play-services-lib. When importing it, be sure to select the "Copy projects into workspace" checkbox. This will create a copy of the project in the SDK directory in your workspace, rather than just linking it.

Now you should be able to go to properties -> Android and select the google-play-services-library

Additionally, be sure to replace xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads" with xmlns:ads="http://schemas.android.com/apk/res-auto"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM