android.util.AndroidRuntimeException:您不能结合滑动解除和操作栏
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24587218/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar
提问by user3797788
I'm new to android programming and started a sample hello world program, but stuck with below error:
我是 android 编程的新手并开始了一个示例 hello world 程序,但遇到以下错误:
07-05 13:52:20.830: W/dalvikvm(898): threadid=1: thread exiting with uncaught exception (group=0xb2ac4d70)
07-05 13:52:20.850: E/AndroidRuntime(898): FATAL EXCEPTION: main
07-05 13:52:20.850: E/AndroidRuntime(898): Process: com.example.helloandroid, PID: 898
07-05 13:52:20.850: E/AndroidRuntime(898): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.MainActivity}: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.access0(ActivityThread.java:138)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.os.Handler.dispatchMessage(Handler.java:102)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.os.Looper.loop(Looper.java:136)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.main(ActivityThread.java:5026)
07-05 13:52:20.850: E/AndroidRuntime(898): at java.lang.reflect.Method.invokeNative(Native Method)
07-05 13:52:20.850: E/AndroidRuntime(898): at java.lang.reflect.Method.invoke(Method.java:515)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
07-05 13:52:20.850: E/AndroidRuntime(898): at dalvik.system.NativeStart.main(Native Method)
07-05 13:52:20.850: E/AndroidRuntime(898): Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:275)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2872)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3129)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:303)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Activity.setContentView(Activity.java:1930)
07-05 13:52:20.850: E/AndroidRuntime(898): at com.example.helloandroid.MainActivity.onCreate(MainActivity.java:13)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Activity.performCreate(Activity.java:5242)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
07-05 13:52:20.850: E/AndroidRuntime(898): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2161)
Manifest file:
清单文件:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloandroid"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.helloandroid.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.Java
主Activity.Java
package com.example.helloandroid;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml
活动_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</RelativeLayout>
Please help me to find out where I'm going wrong, I am currently on Android 4.3, API 18,
请帮我找出我哪里出错了,我目前使用的是 Android 4.3,API 18,
I've tried Android 4.0.3 API 15, Android 4.4W API 20; I have also tried editing sdk as below, but no luck.
我试过 Android 4.0.3 API 15,Android 4.4W API 20;我也尝试过如下编辑 sdk,但没有运气。
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="19" />
回答by SHASHIDHAR MANCHUKONDA
4.4W is Android Wear SDK. (dont target to android wear device)
4.4W 是 Android Wear SDK。(不要针对安卓穿戴设备)
try changing target sdk version to 19
尝试将目标 sdk 版本更改为 19
check here targetSdkVersion setting
在此处检查targetSdkVersion 设置
Do not use API Level of 20 and Platform 4.4W (which is Android Wear SDK) as Android Virtual Device.
不要使用 API Level 20 和 Platform 4.4W(即 Android Wear SDK)作为 Android 虚拟设备。
Use API level 19 and platform 4.4.2 everything works fine.
使用 API 级别 19 和平台 4.4.2 一切正常。
回答by Gangadhar Chowdary Payyavula
I had the same issue. But sdk version was not the cause for this exception.
我遇到过同样的问题。但是 sdk 版本不是此异常的原因。
In the AndroidManifest.xml file you have the theme has ActionBar in it.
在 AndroidManifest.xml 文件中,您的主题中有 ActionBar。
android:theme="@style/AppTheme" >
Change the above line to
将上面的行更改为
android:theme="@android:style/Theme.DeviceDefault" >
That will fix the exception.
这将修复异常。
回答by vinksharma
4.4W is Android Wear SDK.
4.4W 是 Android Wear SDK。
This error is because the device you are targeting is Android Wear which has a different design pattern.
此错误是因为您定位的设备是具有不同设计模式的 Android Wear。
If you are developing a mobile application, change your AVD and target any API below 20 or choose API 20 (L preview).
如果您正在开发移动应用程序,请更改您的 AVD 并针对低于 20 的任何 API 或选择 API 20(L 预览版)。
Or if you are really targeting for Android Wear, change your app design.
或者,如果您真的针对 Android Wear,请更改您的应用程序设计。
回答by user989383
Am using Android Studio beta 0.8.6 with java 7. I had the same issue. And fixed it this way.
我正在使用带有 java 7 的 Android Studio beta 0.8.6。我遇到了同样的问题。并以这种方式修复它。
In the AndroidManifest.xml file you have the theme has ActionBar in it.
在 AndroidManifest.xml 文件中,您的主题中有 ActionBar。
android:theme="@style/AppTheme" >
Change the above line to
将上面的行更改为
android:theme="@android:style/Theme.DeviceDefault" >
That will fix the exception. As mentioned by Gangadhar in prev answer ,sdk version was not the cause for this exception.
这将修复异常。正如 Gangadhar 在上一个回答中提到的,sdk 版本不是此异常的原因。
And tested it with helloWorld app.
并使用 helloWorld 应用程序对其进行了测试。
回答by user3918631
I got this error because I tried to run the mobile part of a wear project on the Samsung Gear device. After switching from "mobile" to "wear" in the run configurations, everything worked (API level 20 and platform 4.4W is indeed the right choice in this case).
我收到此错误是因为我尝试在 Samsung Gear 设备上运行磨损项目的移动部分。在运行配置中从“移动”切换到“穿戴”后,一切正常(在这种情况下,API 级别 20 和平台 4.4W 确实是正确的选择)。
回答by user1544900
go to values/styles.xml and set the styles as follow:
转到 values/styles.xml 并设置样式如下:
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Also, in folders res/values-v11 and res/values-v14, and all folders in values-vxx change the styles.xml file as follows:
此外,在文件夹 res/values-v11 和 res/values-v14 以及 values-vxx 中的所有文件夹中,styles.xml 文件更改如下:
<resources>
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.DeviceDefault">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
You have not to add action bar themes as they are not compatible with wear devices.
您不必添加操作栏主题,因为它们与穿戴式设备不兼容。
回答by TheTall
I got this problem when trying to create the project in Eclipse.
I had to add the following to the manifest file:
尝试在 Eclipse 中创建项目时遇到了这个问题。
我必须将以下内容添加到清单文件中:
<uses-feature android:name="android.hardware.type.watch" />
回答by Sreekumar
Change target sdk version to 19
将目标 sdk 版本更改为 19
Install API level 19 and platform 4.4.2
安装 API 级别 19 和平台 4.4.2
Use API level 19 & platform 4.4.2 while running application in AVD.
在 AVD 中运行应用程序时使用 API 级别 19 和平台 4.4.2。
回答by sashikanta
I have struggle a lot to fix the issue. Nothing work for me except the changes I made in AndroidManifest.xml.
我很难解决这个问题。除了我在 AndroidManifest.xml 中所做的更改之外,没有什么对我有用。
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="21" />
Remove android:targetSdkVersion
, it worked for me, you can also try.
删除android:targetSdkVersion
,它对我有用,您也可以尝试。