1

I am creating one application and i am getting error,

On launching it crash and says

Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

Here is my Activity:

public class SplashScreen extends 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>

Here is my manifest:

 <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>

Here is complete error log:

FATAL EXCEPTION: main 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.social_infotech.renthouse/com.social_infotech.renthouse.activity.SplashScreen}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 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: at 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: at android.os.Looper.loop(Looper.java:137) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5103) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:525) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at 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: Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. 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: at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60) 10-16 15:56:26.135 25342-25342/com.social_infotech.renthouse E/AndroidRuntime: at com.social_infotech.renthouse.activity.SplashScreen.onCreate(SplashScreen.java:16)

piyush poriya
  • 316
  • 1
  • 3
  • 18

5 Answers5

0

Extends your activity with FragmentActivity or Activity Because you are using NoAcionBar as your theme.

Danial Hussain
  • 2,488
  • 18
  • 38
0

for a noActionBar activity :

style.xml

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">

</style>

AndroidManifest.xml

<activity
   android:name=".SplashScreenActivity"
   android:theme="@style/AppThemeNoActionBar" >
</activity>

SplashScreen.java

import android.support.v7.app.AppCompatActivity;
public class SplashscreenActivity extends AppCompatActivity {
   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splashscreen);
   }
}
Chawki Messaoudi
  • 714
  • 2
  • 6
  • 18
0

As I've said, something's not adding up.

You seem to be using different themes:

In the manifest you have

@style/AppTheme1

while the styles file contains

@style/AppTheme
Simas
  • 43,548
  • 10
  • 88
  • 116
0

Just copy your following code to your values-21 >>> Styles.xml then clean your project and try to run.

<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>
Sanket Shah
  • 4,352
  • 3
  • 21
  • 41
0

Please refer to this thread.

EDIT: A few answer from the above thread may help you with this issue. I'll list a summary:

  1. molokoka's answer, in order to add ActionBarCompat in your activity or application should use @style/Theme.AppCompat theme in AndroidManifest.xml like this:

<activity ... android:theme="@style/Theme.AppCompat" />

molokoka also states that usually you need to customize your ActionBar. Once again, please follow his answer for details.

  1. tyczj also makes a very good point: Check and make sure that you do not have another values folder that references theme.styled and does not use AppCompat theme

ie values-v11 folder.

Side note: Sorry, I'm unable to add a comment due to low reputation. That's the reason why I placed an answer.

Community
  • 1
  • 1
AuroMetal
  • 928
  • 3
  • 14
  • 32
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Anirudh Sharma Oct 21 '15 at 05:10
  • @Anirudh Sharma, apologies. I hope the edit can help not only the OP, but anyone who may need it. – AuroMetal Oct 21 '15 at 07:16