我創建一個應用程序,我收到錯誤崩潰,我的活動延伸AppCompatActivity和啓動
在啓動它崩潰,說
產生的原因:java.lang.IllegalStateException:您需要Theme.AppCompat主題(或後代)與此活動一起使用 。
這裏是我的活動:
公共類閃屏擴展AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreen.this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
finish();
}
}, 3000);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_splash_screen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
<!-- Base application theme. -->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/accent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@style/MyAnimation.Window</item>
<item name="android:windowBackground">@color/background</item>
</style>
<!-- Application theme. -->
<style name="AppTheme1" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
這裏是我的清單:
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme1" >
<activity
android:name=".activity.SplashScreen"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
下面是完整的錯誤日誌:
致命異常:主要10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: 了java.lang.RuntimeException:無法啓動活動 ComponentInfo {com.social_infotech.renthouse/com.social_infotech.renthouse.activity.SplashScreen}: java.lang.IllegalStateException:您需要在此活動中使用Theme.AppCompat 主題(或後代)。 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211) 10-16 15:56:26.135 25342-25342 /com.social_infotech.renthouse E/AndroidRuntime:在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at android.app.ActivityThread.access $ 600(ActivityThread.java:141)10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at android.app.ActivityThread $ H。 handleMessage(ActivityThread.java:1256) 10- 16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at android.os.Handler.dispatchMessage(Handler.java:99)10-16 15:56:26.135 25342-25342/com .social_infotech.renthouse E/AndroidRuntime:在 android.os.Looper.loop(Looper.java:137)10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:在 android。 E/AndroidRuntime:在java.lang.reflect.Method.invokeNative(原生 方法)10/15 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:在java.lang.reflect.Method.invokeNative(原生 方法) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:在 java.lang.reflect.Method.invoke(M ethod.java:525)10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:在 com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)10-16 15:56 :26。135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at dalvik.system.NativeStart.main(Native Method) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:由於:java.lang.IllegalStateException:您需要使用Theme.AppCompat主題(或後代)與此 活動使用 。 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at android.support.v7.app.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:112) 10-16 15:56: 26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime:at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:148) 10-16 15:56:26.135 25342-25342/com。 social_infotech.renthouse E/AndroidRuntime:在 android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime :在 com.social_infotech.renthouse.activity.SplashScreen.onC由於您使用NoAcionBar作爲你的主題reate(SplashScreen.java:16)
檢查清單,確保您的活動使用'@風格/ AppTheme'或'@風格/ AppBaseTheme'。 – Simas
我的清單使用了android:theme =「@ style/AppTheme」 –
您是否包含appCompat支持庫作爲庫 –