简体   繁体   English

膨胀com.google.ads.AdView时出错

[英]Error inflating com.google.ads.AdView

I am trying to integrate google ads to my game. 我正在尝试将Google广告集成到我的游戏中。 But when I run this code, I got an exception. 但是,当我运行此代码时,出现了异常。 Here is my code: 这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
          android:orientation="horizontal"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@drawable/podklad">
<com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="ca-app-pub-7921725136909046/2004996412"
        ads:adSize="BANNER"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"/>

I deleted some button definitions because they are not important 我删除了一些按钮定义,因为它们并不重要

and this is my logcat: 这是我的日志:

Process: com.tproductions.monstertap, PID: 5846
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tproductions.monstertap/com.tproductions.monstertap.MainMenuActivity}: android.view.InflateException: Binary XML file line #51: Error inflating class com.google.android.gms.ads.AdView
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
        at android.app.ActivityThread.access$800(ActivityThread.java:144)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:212)
        at android.app.ActivityThread.main(ActivityThread.java:5135)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:877)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
        at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.view.InflateException: Binary XML file line #51:       Error inflating class com.google.android.gms.ads.AdView
        at android.view.LayoutInflater.createView(LayoutInflater.java:620)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:696)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297)
        at android.app.Activity.setContentView(Activity.java:1929)
        at com.tproductions.monstertap.MainMenuActivity.onCreate(MainMenuActivity.java:34)
        at android.app.Activity.performCreate(Activity.java:5231)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)   

Is there a reason you using " http://schemas.android.com/apk/lib/com.google.ads " as your namespace for the ads attributes? 您是否有理由将“ http://schemas.android.com/apk/lib/com.google.ads ”用作广告属性的命名空间? The package names for it and the tag do not correspond. 它的软件包名称和标签不对应。

Try " http://schemas.android.com/apk/res-auto " (see https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#step_1_create_fragment_adxml ) 尝试“ http://schemas.android.com/apk/res-auto ”(请参阅https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#step_1_create_fragment_adxml

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

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