Unable to resolve error Theme.AppCompat theme (or descendant) - android

I looked at other SO posts and configured accordingly. But I still see this issue on some Android devices (4.3.1). It works 75% of time.
You need to use a Theme.AppCompat theme (or descendant) with this activity.
What is wrong with code below?
BaseActivity extends android.support.v7.appAppCompatActivity
<application
android:allowBackup="true"
android:theme="#style/AppTheme" >
All activities (crashed acitivity as well) use AppTheme from application tag. One activity uses:
<activity
android:name=".Activities.EntryActivity"
android:noHistory="true"
android:theme="#style/SplashTheme" >
I don't have any other style.xml.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
From Android:
<style name="Theme.AppCompat.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
java.lang.RuntimeException: Unable to start activity
ComponentInfo{Activities.MyAcitivity}:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity. 1 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
2 at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
3 at android.app.ActivityThread.access$600(ActivityThread.java:141)
4 at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
5 at android.os.Handler.dispatchMessage(Handler.java:99) 6 at
android.os.Looper.loop(Looper.java:137) 7 at
android.app.ActivityThread.main(ActivityThread.java:5103) 8 at
java.lang.reflect.Method.invokeNative(Native Method) 9 at
java.lang.reflect.Method.invoke(Method.java:525) 10 at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
11 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
12 at com.android.internal.os.ZygoteInit.main(Native Method) 13 at
dalvik.system.NativeStart.main(Native Method) 14 Caused by:
java.lang.IllegalStateException: You need to use a Theme.AppCompat
theme (or descendant) with this activity. 15 at
android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 16 at
android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 17 at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273)
18 at
android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136)
19 at .Commons.BaseActivity.onCreate(SourceFile:236) 20 at
.MyActivity.onCreate(SourceFile:24) 21 at
android.app.Activity.performCreate(Activity.java:5133) 22 at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
23 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
24 ... 12 more 25 java.lang.IllegalStateException: You need to use a
Theme.AppCompat theme (or descendant) with this activity. 26 at
android.support.v7.app.AppCompatDelegateImplV7.i(SourceFile:340) 27 at
android.support.v7.app.AppCompatDelegateImplV7.h(SourceFile:309) 28 at
android.support.v7.app.AppCompatDelegateImplV7.setContentView(SourceFile:273)
29 at
android.support.v7.app.AppCompatActivity.setContentView(SourceFile:136)
30 at Activities.Commons.BaseActivity.onCreate(SourceFile:236) 31 at
Activities.Accounts.AppLaunchActivity.onCreate(SourceFile:24) 32 at
android.app.Activity.performCreate(Activity.java:5133) 33 at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
34 at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
35 at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
36 at android.app.ActivityThread.access$600(ActivityThread.java:141)
37 at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
38 at android.os.Handler.dispatchMessage(Handler.java:99) 39 at
android.os.Looper.loop(Looper.java:137) 40 at
android.app.ActivityThread.main(ActivityThread.java:5103) 41 at
java.lang.reflect.Method.invokeNative(Native Method) 42 at
java.lang.reflect.Method.invoke(Method.java:525) 43 at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
44 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
45 at com.android.internal.os.ZygoteInit.main(Native Method) 46 at
dalvik.system.NativeStart.main(Native Method)

try this:
in res/values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.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>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
Now in your manifest:
<application
android:theme="#style/AppTheme"> //base Application theme
<activity
android:name=".Activities.EntryActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar"> //Activity Theme
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

Related

my activity extends AppCompatActivity and crash on Launch

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)
Extends your activity with FragmentActivity or Activity
Because you are using NoAcionBar as your theme.
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
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>
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);
}
}
Please refer to this thread.
EDIT: A few answer from the above thread may help you with this issue. I'll list a summary:
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.
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.

Why is this android app crashing on the emulator?

I have been attempting to run this application from this repository
https://github.com/tekinarslan/AndroidMaterialDesignToolbar
But each time it crashes with the following message
07-26 11:36:39.864 4405-4405/com.tekinarslan.material.sample E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tekinarslan.material.sample/com.tekinarslan.material.sample.SampleActivity}: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: AppCompat does not support the current theme features
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:360)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:246)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.tekinarslan.material.sample.SampleActivity.onCreate(SampleActivity.java:36)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
The following is the build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.tekinarslan.material.sample"
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
}
And this is the styles.xml file
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>
<style name="AppTheme.Base" parent="Theme.AppCompat">
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:windowNoTitle">true</item>
<item name="windowActionBar">false</item>
<item name="drawerArrowStyle">#style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="spinBars">true</item>
<item name="color">#android:color/white</item>
</style>
</resources>
It shows the same message even after I replace ActionBarActivity with AppCompatActivity in the SampleActivity.java file..Please help
Replacing android:windowNoTitle with just windowNoTitle fixes the issue.
Had similar problem and
https://blog.xamarin.com/android-tips-hello-material-design-v7-appcompat/
fixed using suggestion given in this link.
<!--If you are using revision 22.1 please use just windowNoTitle. Without android:-->
<item name="windowNoTitle">true</item>
If your intention is to not use actionbar at all and use only toolbar, you can use Theme.AppCompat.NoActionBar as parent. (This I have tried on your git code and it works).

Why won't my Android App open in Fullscreen?

I know that this question has been asked before, but the provided answers did not solve my case, so I'll ask for an individual solution.
My code
My AndroidManifest.xml looks like this:
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
>
<activity
android:name=".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=".KategorieAuswahl"
android:label="#string/title_activity_kategorie_auswahl" >
</activity>
<activity
android:name=".ZeigeFragen"
android:label="#string/title_activity_zeige_fragen" >
</activity>
</application>
And my styles.xml looks like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
</resources>
I want my App to open in fullscreen and to hide the TitleBar. The first thing I did was to add a android:theme="#android:style/Theme.NoTitleBar.Fullscreen" attribute to the <application>-Tag of my AndroidManifest.xml.
This leads to the error You need to use a Theme.AppCompat theme (or descendant) with this activity. Here is the full stacktrace:
05-27 21:24:26.889 2121-2121/de.test.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{de.test.myapp/de.test.myapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
at android.app.ActivityThread.access$600(ActivityThread.java:130)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
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:113)
at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
at de.test.myapp.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
            at android.app.ActivityThread.access$600(ActivityThread.java:130)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4745)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
            at dalvik.system.NativeStart.main(Native Method)
There are multiple questions on stackoverflow referencing this error.
Approach #1
One solution suggests to change the Java inheritance from ActionBarActivity to Activity and leave the manifest as it is.
So I updated my the <style> element in my styles.xml and removed the DarkActionBar part:
<style name="AppTheme" parent="Theme.AppCompat.Light">
This still gives me the same error.
Approach #2
The next solution suggests to change my styles.xml's parent attribute from
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
to <style name="AppTheme" parent="Theme.AppCompat">
This makes it possible to use android:theme="#style/Theme.AppCompat.NoActionBar" for my <activity>, but I don't see an option to make it fullscreen then.
Approach #3
Another solution soggests to add <item name="android:windowNoTitle">true</item> to my <style> element but this doesn't change anything at all.
Conclusion
I really tried a lot, but nothing seems to work. Anyway I have problems understanding the theme inheritance chain and when I may use .NoTitleBar and .Fullscreen.
After all I don't care which theme to use, as long I can make the app fullscreen without a title bar. Can you help me to pick the right attributes?
extend ActionBarActivity or the new one, and use Theme.AppCompat.NoActionBar, now in your Activity
if (Build.VERSION.SDK_INT < 16) {
Activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
Activity.getWindow().getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
Hope it helps..

Activity could not be started due to support ActionBar's class cast exception

From one android.support.v7.app.ActionBarActivity I'm starting another android.support.v7.app.ActionBarActivity activity, but getting this Exception:
FATAL EXCEPTION: main
Process: com.playgong.stg.dbg, PID: 32299
java.lang.ClassCastException: android.support.v7.internal.widget.ActionBarOverlayLayout$LayoutParams cannot be cast to com.android.internal.widget.ActionBarOverlayLayout$LayoutParams
at com.android.internal.widget.ActionBarOverlayLayout.applyInsets(ActionBarOverlayLayout.java:172)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:317)
at android.view.View.measure(View.java:16497)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5125)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2291)
at android.view.View.measure(View.java:16497)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1912)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1109)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1291)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:996)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5600)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
First activity has style
<style name="PS" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowContentTransitions">true</item>
</style>
Second (that which is crashing):
<style name="PS.Second" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/PS.ActionBar</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
</style>
Any ideas how to avoid ClassCastException?
I am not sure what is PS.ActionBar style. So I commented that out. And tried the same thing on my Device Moto G API 21. I don't see the crash.
That being said, this crash appears to be an internal one. Besides ActionBarActivity has been deprecated, instead use AppCompatActivity.
PS: I am still waiting for your answer, so I could edit my answer with more findings.
I got this error because I was not using a activity theme which has no action bar. Using the following theme set in the manifest for the activity works:
<style name="mytheme.NoActionBar" parent="AppTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
the other pecular thing is that it only occured on kitkat.

Error using TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse

Encountered this error trying to style the ActionBar title, on API 10, using the latest v7 appcompat support lib (r21, Lollipop). Works fine on API 15+ though.
my same code used to work fine until this r21 came along, causing many problems.
stack trace:
11-05 02:08:49.628: E/AndroidRuntime(527): Caused by: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
11-05 02:08:49.628: E/AndroidRuntime(527): at android.content.res.TypedArray.getColor(TypedArray.java:326)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.widget.TextView.setTextAppearance(TextView.java:1616)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.widget.Toolbar.setTitle(Toolbar.java:579)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.internal.widget.ToolbarWidgetWrapper.setTitleInt(ToolbarWidgetWrapper.java:285)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.internal.widget.ToolbarWidgetWrapper.setWindowTitle(ToolbarWidgetWrapper.java:267)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.internal.widget.ActionBarOverlayLayout.setWindowTitle(ActionBarOverlayLayout.java:679)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.app.ActionBarActivityDelegateBase.onTitleChanged(ActionBarActivityDelegateBase.java:461)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.support.v7.app.ActionBarActivity.onTitleChanged(ActionBarActivity.java:176)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.app.Activity.onPostCreate(Activity.java:916)
11-05 02:08:49.628: E/AndroidRuntime(527): at android.app.Instrumentation.callActivityOnPostCreate(Instrumentation.java:1108)
My app's res/styles.xml:
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
<item name="actionBarStyle">#style/AppBaseTheme.ActionBar</item>
</style>
<style name="AppBaseTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid">
<item name="titleTextStyle">#style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse</item>
</style>
v7 appcompat res/styles_base_text.xml:
53 <style name="Base.TextAppearance.AppCompat.Title">
54 <item name="android:textSize">#dimen/abc_text_size_title_material</item>
55 <item name="android:textColor">?android:textColorPrimary</item>
56 </style>
57
58 <style name="Base.TextAppearance.AppCompat.Title.Inverse">
59 <item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
60 <item name="android:textColorHint">?android:attr/textColorHintInverse</item>
61 <item name="android:textColorHighlight">?android:attr/textColorHighlightInverse</item>
62 <item name="android:textColorLink">?android:attr/textColorLinkInverse</item>
63 </style>
However, once I removed the ".Inverse" in my styles.xml, it works fine.
It crashes at this line http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3_r1/android/widget/TextView.java/#1616
while trying to get the colorHightlight.
Any idea how to fix?
It may be that in API 10 there is no Base.TextAppearance.AppCompat.Title.Inverse theme.
You should check if the theme is present in API 10.
A solution may be to define a common base theme that inherits from a different parent theme included in API 10.
res/values-v10/themes.xml:
<style name="Base.TextAppearance.AppCompat.Title">
<item name="android:textColor">?android:attr/textColorPrimaryInverse</item>
<item name="android:textColorHint">?android:attr/textColorHintInverse</item>
<item name="android:textColorHighlight">16842905</item>
<item name="android:textColorLink">?android:attr/textColorLinkInverse</item>
</style>
You can definitely see that textColorHighlightInverse is not present in API level 10.
Check this textColorHighlightInverse link and select API level 10 in left menu.
Also have a look at this https://code.google.com/p/android/issues/detail?id=18659

Categories

Resources