在com.google.ads.Adview Android类中输入错误

时间:2014-03-07 15:36:09

标签: android eclipse admob logcat android-logcat

我对编码很新(我在市场上有一些应用程序,但还没有游戏)因此我决定创建一个游戏。我制作了整个游戏并且它有效,但是当我尝试整合Google AdMob时,一切都出错了。

这是我的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>

这是我的清单

<?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>

这是我的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

如果有人能告诉我出了什么问题以及如何解决它,我将非常感激。

感谢您

2 个答案:

答案 0 :(得分:0)

staktrace明确表示无法找到com.google.ads.Adview。

您需要将包含该类的库添加到APK。这可能是Google Play服务或Google Admob SDK-6.4.1,具体取决于您使用哪个与Admob集成。

答案 1 :(得分:0)

听起来你需要做的第一件事就是将google-play-services-lib导入Eclipse(你的评论听起来好像你正在使用Eclipse)。转到文件 - &gt;导入 - &gt; Android - &gt;现有Android代码进入工作区。浏览SDK目录中的Google Play服务库。默认情况下,它通常低于C:/Users/[username]/AppData/Local/Android/extras/google/google_play_services/libproject。选择google-play-services-lib。导入时,请务必选中“将项目复制到工作区”复选框。这将在工作区的SDK目录中创建项目的副本,而不仅仅是链接它。

现在你应该可以去房产 - &gt; Android并选择google-play-services-library

此外,请务必将xmlns:ads= "http://schemas.android.com/apk/lib/com.google.ads"替换为xmlns:ads="http://schemas.android.com/apk/res-auto"