开始的Android应用程序崩溃

时间:2018-07-29 12:24:14

标签: android-studio

我是android开发的初学者,我在模拟器上遇到以下错误,我试图通过搜索找到解决方案,但这很难找到,因此如果有人可以解决但需要更多详细信息告诉我

 --------- beginning of crash
07-26 19:26:25.280 2672-2672/? E/AndroidRuntime: FATAL EXCEPTION: main
    Process: meddevelopers.labresultsworldwide, PID: 2672
    java.lang.RuntimeException: Unable to start activity ComponentInfo{meddevelopers.labresultsworldwide/meddevelopers.labresultsworldwide.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6077)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.support.v7.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:553)
        at android.support.v7.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:516)
        at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:464)
        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
        at meddevelopers.labresultsworldwide.MainActivity.onCreate(MainActivity.java:13)
        at android.app.Activity.performCreate(Activity.java:6662)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
        at android.app.ActivityThread.-wrap12(ActivityThread.java) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:154) 
        at android.app.ActivityThread.main(ActivityThread.java:6077) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756) 

我试图对清单文件进行一些编辑,但是所有编辑都没有用,所以我将其复制给了您

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="meddevelopers.labresultsworldwide">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".abbreviations" />
        <activity android:name=".hematology" />
        <activity android:name=".RBC" />
        <activity android:name=".wbc" />
        <activity android:name=".hgb" />
        <activity android:name=".hct" />
        <activity android:name=".mch" />
        <activity android:name=".mcv" />
        <activity android:name=".mchc" />
        <activity android:name=".rdw" />
        <activity android:name=".plt" />
        <activity android:name=".mpv" />
        <activity android:name=".neu" />
        <activity android:name=".lympho" />
        <activity android:name=".mono" />
        <activity android:name=".eos" />
        <activity android:name=".baso" />
        <activity android:name=".arterialvalues" />
        <activity android:name=".cardiacmarker" />
        <activity android:name=".ck" />
        <activity android:name=".ckmb" />
        <activity android:name=".ldh" />
        <activity android:name=".ast" />
        <activity android:name=".troponin" />
        <activity android:name=".myoglobin" />
        <activity android:name=".bodyfluids" />
        <activity android:name=".csf" />
        <activity android:name=".pf" />
        <activity android:name=".semenf" />
        <activity android:name=".coagulation" />
        <activity android:name=".endocrine" />
        <activity android:name=".hemodynamic" />
        <activity android:name=".lipid" />
        <activity android:name=".neurological" />
        <activity android:name=".urine" />
        <activity android:name=".urine24" />
        <activity android:name=".alal" />
        <activity android:name=".generalchem" />

        <meta-data
            android:name="preloaded_fonts"
            android:resource="@array/preloaded_fonts" />

    </application>

</manifest>

在一些搜索中,我认为问题出在主题上,但我也无法解决

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">


    <!-- Customize your theme here. -->

        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>

    </style>

</resources>

我该怎么解决?

1 个答案:

答案 0 :(得分:0)

每当我们使用AppCompatActivity时,都必须使用Theme.AppCompat或其后代。如果您想使用其他主题,只需使用android.app.Activity。