如何在我的android sdk xml中使用谷歌广告暴徒

时间:2014-09-02 01:14:16

标签: admob

我正在尝试在我的android sdk应用上添加admob。我正在关注链接:https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start

我不确定为什么或如何解决此错误。我不确定我错过了什么。

堆栈:

09-02 00:49:15.040: E/AndroidRuntime(754): FATAL EXCEPTION: main
09-02 00:49:15.040: E/AndroidRuntime(754): Process: com.example.pingpong, PID: 754
09-02 00:49:15.040: E/AndroidRuntime(754): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pingpong/com.a.pingpong.mainMenu}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.os.Handler.dispatchMessage(Handler.java:102)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.os.Looper.loop(Looper.java:136)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread.main(ActivityThread.java:5026)
09-02 00:49:15.040: E/AndroidRuntime(754):  at java.lang.reflect.Method.invokeNative(Native Method)
09-02 00:49:15.040: E/AndroidRuntime(754):  at java.lang.reflect.Method.invoke(Method.java:515)
09-02 00:49:15.040: E/AndroidRuntime(754):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-02 00:49:15.040: E/AndroidRuntime(754):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
 09-02 00:49:15.040: E/AndroidRuntime(754):     at dalvik.system.NativeStart.main(Native Method)
 09-02 00:49:15.040: E/AndroidRuntime(754): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
 09-02 00:49:15.040: E/AndroidRuntime(754):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
 09-02 00:49:15.040: E/AndroidRuntime(754):     at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
 09-02 00:49:15.040: E/AndroidRuntime(754):     at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
09-02 00:49:15.040: E/AndroidRuntime(754):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.Activity.setContentView(Activity.java:1930)
09-02 00:49:15.040: E/AndroidRuntime(754):  at com.a.pingpong.mainMenu.onCreate(mainMenu.java:23)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.Activity.performCreate(Activity.java:5242)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 00:49:15.040: E/AndroidRuntime(754):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
09-02 00:49:15.040: E/AndroidRuntime(754):  ... 11 more
09-02 00:52:59.490: D/AndroidRuntime(804): Shutting down VM
09-02 00:52:59.490: W/dalvikvm(804): threadid=1: thread exiting with uncaught exception (group=0xb3a8bd70)
09-02 00:52:59.510: E/AndroidRuntime(804): FATAL EXCEPTION: main
09-02 00:52:59.510: E/AndroidRuntime(804): Process: com.example.pingpong, PID: 804
09-02 00:52:59.510: E/AndroidRuntime(804): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pingpong/com.a.pingpong.mainMenu}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread.access$800(ActivityThread.java:138)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.os.Handler.dispatchMessage(Handler.java:102)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.os.Looper.loop(Looper.java:136)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread.main(ActivityThread.java:5026)
 09-02 00:52:59.510: E/AndroidRuntime(804):     at java.lang.reflect.Method.invokeNative(Native Method)
 09-02 00:52:59.510: E/AndroidRuntime(804):     at java.lang.reflect.Method.invoke(Method.java:515)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
09-02 00:52:59.510: E/AndroidRuntime(804):  at dalvik.system.NativeStart.main(Native Method)
09-02 00:52:59.510: E/AndroidRuntime(804): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.Activity.setContentView(Activity.java:1930)
09-02 00:52:59.510: E/AndroidRuntime(804):  at com.a.pingpong.mainMenu.onCreate(mainMenu.java:23)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.Activity.performCreate(Activity.java:5242)
 09-02 00:52:59.510: E/AndroidRuntime(804):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
09-02 00:52:59.510: E/AndroidRuntime(804):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
09-02 00:52:59.510: E/AndroidRuntime(804):  ... 11 more

的AndroidManifest.xml

<uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />
...
 <application
        ....
        >

         <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
         .......

        <activity android:name="com.google.android.gms.ads.AdActivity"          android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>

layout.xml

<LinearLayout 
        ...
    xmlns:ads = "http://schemas.android.com/apk/lib/com.google.ads"
    ....
    >

     <com.google.android.gsm.ads.AdView
        android:id = "@+id/adView"
        android:layout_width = "fill_parent"
        android:layout_height = "wrap_content"
        ads:adUnitId = "ea-eap-vav-1123185352332330/2222333344"
        ads:adSize = "BANNER"
        ads:testDevices = "TEST_EMULATOR, samsung-samsung_si_f910e-awc34ed0"
        ads:loadAdOnCreate = "true" />

mainMenu.java

protected void onCreate(Bundle savedInstanceState) {
    ....
    // Look up the AdView as a resource and load a request.
        AdView adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);
 }

1 个答案:

答案 0 :(得分:0)

来自logcat报告:

 "09-02 00:52:59.510: E/AndroidRuntime(804): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar."

您似乎正在使用4.4W这是Android Wear SDK。

抛出异常是因为您正在测试应用的设备是Android Wear,它具有不同的设计模式。

不要将API等级20和平台4.4W用作(AVD)Android虚拟设备。 将您的AVD更改为目标任何低于20的API(示例:选择API级别19或API 20(L预览))。

另外,在我们的布局xml文件中,请确保更改:

xmlns:ads = "http://schemas.android.com/apk/lib/com.google.ads"

为:

xmlns:ads="http://schemas.android.com/apk/res-auto"

因为您通过Google Play服务库使用了admob。