简体   繁体   English

膨胀类com.google.ads.Adview Android时出错

[英]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. 我完成了整个游戏,但效果很好,但是当我尝试集成Google AdMob时,一切都出错了。

Here is my main.xml (the place I want the ads) 这是我的main.xml(我想要广告的地方)

<?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 这是我的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. 该staktrace明确表示找不到com.google.ads.Adview。

You need to add the library containing that class to your APK. 您需要将包含该类的库添加到您的APK。 That is either Google Play Services or Google Admob SDK-6.4.1 depending on which you are using to integrate with Admob. 这取决于您用来与Admob集成的Google Play服务或Google Admob SDK-6.4.1。

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). 听起来您需要做的第一件事是将google-play-services-lib导入Eclipse(您的注释听起来就像您正在使用Eclipse)。 Go to File -> Import -> Android -> Existing Android Code Into Workspace. 转到文件->导入-> Android->现有的Android代码到工作区。 Browse to the Google Play Services Library in your SDK directory. 浏览到SDK目录中的Google Play服务库。 By default it is usually under C:/Users/[username]/AppData/Local/Android/extras/google/google_play_services/libproject . 默认情况下,它通常位于C:/Users/[username]/AppData/Local/Android/extras/google/google_play_services/libproject Select the google-play-services-lib. 选择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. 这将在工作区的SDK目录中创建项目的副本,而不仅仅是链接它。

Now you should be able to go to properties -> Android and select the google-play-services-library 现在,您应该可以转到属性-> Android并选择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" 另外,请确保将xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"替换为xmlns:ads="http://schemas.android.com/apk/res-auto"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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