gpt4 book ai didi

java - Android应用程序不断崩溃。帮助新手?

转载 作者:行者123 更新时间:2023-12-03 17:32:11 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat

(13 个回答)


8年前关闭。




我最近开始学习开发 android 代码。在我尝试集成 v7-appcompat 以允许使用操作栏之前,我让这个简单的程序运行良好。现在我的程序在启动时立即崩溃。有任何想法吗?

日志猫:

02-27 21:15:14.958: D/AndroidRuntime(680): Shutting down VM
02-27 21:15:14.958: W/dalvikvm(680): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-27 21:15:14.969: E/AndroidRuntime(680): FATAL EXCEPTION: main
02-27 21:15:14.969: E/AndroidRuntime(680): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mikemiles/com.mikemiles.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.os.Looper.loop(Looper.java:123)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-27 21:15:14.969: E/AndroidRuntime(680): at java.lang.reflect.Method.invokeNative(Native Method)
02-27 21:15:14.969: E/AndroidRuntime(680): at java.lang.reflect.Method.invoke(Method.java:521)
02-27 21:15:14.969: E/AndroidRuntime(680): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-27 21:15:14.969: E/AndroidRuntime(680): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-27 21:15:14.969: E/AndroidRuntime(680): at dalvik.system.NativeStart.main(Native Method)
02-27 21:15:14.969: E/AndroidRuntime(680): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-27 21:15:14.969: E/AndroidRuntime(680): at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
02-27 21:15:14.969: E/AndroidRuntime(680): at com.mikemiles.MainActivity.onCreate(MainActivity.java:15)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-27 21:15:14.969: E/AndroidRuntime(680): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-27 21:15:14.969: E/AndroidRuntime(680): ... 11 more

提前致谢!

编辑:

mrres1:我自己写的,但按照这里的教程: https://developer.android.com/training/basics/actionbar/setting-up.html

我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal" >

<EditText android:id="@+id/edit_message"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="@string/edit_message" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />

</LinearLayout>

list 文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mikemiles"
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.mikemiles.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>
<activity
android:name="com.mikemiles.DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.mikemiles.myfirstapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mikemiles.myfirstapp.MainActivity" />
</activity>
</application>

</manifest>

最佳答案

添加 android:theme="@style/Theme.AppCompat"在 list 中的 MainActivity

<activity
android:name="com.mikemiles.MainActivity"
android:theme="@style/Theme.AppCompat"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

关于java - Android应用程序不断崩溃。帮助新手?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22085545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com