2014-09-02 43 views
0

我想在我的android sdk應用程序中添加admob。我正在關注該鏈接:https://developers.google.com/mobile-ads-sdk/docs/admob/android/quick-start我該如何在我的android sdk xml中使用谷歌廣告羣

我不知道爲什麼或者如何解決這個錯誤。我不知道我錯過了什麼。

堆棧:

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); 
} 

回答

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 Level 20和Platform 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" 

,因爲您是通過谷歌Play服務庫使用AdMob。

相關問題