Android 不幸的是,我的应用程序已停止错误
我是一个相对较新的Android程序员,在编写了这段代码后,它只要求用户输入信息,然后显示出来。输入消息后单击发送按钮后,它会显示“不幸的是,应用程序已停止” 这是我单击“发送”按钮后日志文件中的错误Android 不幸的是,我的应用程序已停止错误,android,Android,我是一个相对较新的Android程序员,在编写了这段代码后,它只要求用户输入信息,然后显示出来。输入消息后单击发送按钮后,它会显示“不幸的是,应用程序已停止” 这是我单击“发送”按钮后日志文件中的错误 Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.supp
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at com.example.dm4.myapplication.DisplayMessageActivity.onCreate(DisplayMessageActivity.java:15)
at android.app.Activity.performCreate(Activity.java:6010)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1129)
在
style.xml中创建一个新主题
<style name="ActionbarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">@color/ColorPrimary</item>
<item name="android:titleTextStyle">@style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="android:icon">@android:color/transparent</item>
</style>
@样式/MyActionBar
@颜色/原色
@style/Theme.MyAppTheme.ActionBar.TitleTextStyle
@android:彩色/透明
现在为您的活动设置主题
<activity
android:name="MainActivity"
android:theme="@style/ActionbarTheme" >
</activity>
您可以这样做:
清单的应用程序标记应如下所示:
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault" >
希望这对您有所帮助。您的按钮在哪里?您需要发布stacktrace。问题可能出现在youtDisplayMessageActivity
class@KenKwok它看起来像文档中的启动应用程序,因此按钮很可能在xml中,并且onClick
也在xml中设置。当我需要使用主题时,这意味着什么。appcompat主题?通过添加主题修复。
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.DeviceDefault" >