执行时(在android监视器控制台上)我收到此错误:
06-16 11:25:38.227 1555-1555/com.example.mysampleapp E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mysampleapp/com.example.mysampleapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
我正在尝试使用this项目在我的应用中集成zxing,并附带说明here。我的清单是这样的:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mysampleapp">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name="android.support.multidex.MultiDexApplication"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="randomkeywhichyoudontneedtoknow" />
</activity>
<activity
android:name=".SplashActivity"
android:label="mysampleapp"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"></activity>
</application>
</manifest>
Styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
(需要在问题中添加一些文字,因此满足stackoverflow,这就是!)
答案 0 :(得分:1)
尝试删除此行:
android:theme="@style/AppTheme.NoActionBar"
来自Activity
。
正如您的样式文件所包含,AppTheme
已使用Theme.AppCompat.Light.NoActionBar
,并且您的清单已在整个应用范围内应用。