我正在尝试将google广告整合到我的游戏中。但是当我运行这段代码时,我得到了一个例外。这是我的代码:
<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"/>
我删除了一些按钮定义,因为它们并不重要
这是我的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)
答案 0 :(得分:0)
你有没有理由使用&#34; http://schemas.android.com/apk/lib/com.google.ads&#34;作为广告属性的命名空间?它的包名和标签不对应。
尝试&#34; http://schemas.android.com/apk/res-auto&#34; (见https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start#step_1_create_fragment_adxml)