ActionBarSherlock with Android Action Bar Style Generator - android

I'm using ActionBarSherlock with Android Action Bar Style Generator (http://jgilfelt.github.io/android-actionbarstylegenerator/) and it works perfectly with API v14+, but on v10-v14, I get the following:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp/com.myapp.loginregistration.Login}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1821)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1842)
at android.app.ActivityThread.access$1500(ActivityThread.java:132)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4263)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:976)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:902)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:836)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
at com.myapp.loginregistration.Login.onCreate(Login.java:25)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1785)
Is there anyway to get the style generator to work with the Api 10-14? Right now I have it set to default to Theme.Sherlock when using the lower API phones, so the bug goes away, but its not the style I would like.

What style would you like?
The theme generator works with stock Android Holo, ActionbarSherlock or Appcompat.
Theme.Sherlock, Theme.Sherlock.Light and Theme.Sherlock.Light.DarkActionbar are all just ports of Holo, Holo.Light, and Holo.Light.DarkActionbar, so any theme that you can get in api 11+, you can get with ActionbarSherlock.
What style are you trying to achieve?

Related

Android 2.3.x crashing on com.google.android.gms.location.LocationSettingsResult.startResolutionForResult

I'm in middle of a big issue,
OS VERSION: Android 2.3.x
DEVICE: GT i9100 (samsung galaxy s II)
LOCATION API: com.google.android.gms:play-services-location:9.4.0
PROBLEM: app crash calling
com.google.android.gms.location.LocationSettingsResult.startResolutionForResult
com.google.android.gms.ui E/AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Binary XML file line #25: You must supply a layout_height attribute.
FATAL EXCEPTION: main
java.lang.RuntimeException: Binary XML file line #25: You must supply a layout_height attribute.
at android.content.res.TypedArray.getLayoutDimension(TypedArray.java:543)
at android.view.ViewGroup$LayoutParams.setBaseAttributes(ViewGroup.java:3599)
at android.view.ViewGroup$MarginLayoutParams.(ViewGroup.java:3678)
at android.widget.LinearLayout$LayoutParams.(LinearLayout.java:1400)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:1326)
at android.widget.LinearLayout.generateLayoutParams(LinearLayout.java:47)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:625)
at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2261)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2316)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1478)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2165)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1672)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
please refer the following link, i've exactly same issue
https://code.google.com/p/android/issues/detail?id=215183
please help me to fix this
Thanks
Please check solution given in this related SO post by #frieza if it can help.
As suggested, aside from defining layout_height and layout_width attributes shown in the posted codes, you might need to also set parent attribute with parent="android:Theme".
Hope that works for you too.

Android: getting Resources$NotFoundException for abc_ic_ab_back_material

I'm getting a Resources$notfoundexception on older (pre-L) devices. I'm including the full stacktrace below.
My version of the support library is the latest (24.1.0), and I've included in my gradle file the line:
vectorDrawables.useSupportLibrary = true
My base theme is a noactionbar theme - "Theme.AppCompat.Light.NoActionBar"
The crash is happening on this line in my code where I reference the back arrow in a support-toolbar in order to later change it's color:
#SuppressLint("PrivateResource") final Drawable upArrow = ContextCompat.getDrawable(this, R.drawable.abc_ic_ab_back_material);
What could be the cause of this? This code works fine for all users with L or above.
07-19 22:36:57.029 9330-9330/mypkg E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to resume activity {mypkg/mypkg.activites.myActivity}: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2619)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
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:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/abc_ic_ab_back_material.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:1957)
at android.content.res.Resources.getDrawable(Resources.java:673)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
at mypkg.base.mymethod(myactivity.java:100)
at mypkg.mymethod(myactivity.java:100)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:511)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:178)
at android.app.Activity.performResume(Activity.java:5341)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
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:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #17: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:877)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:818)
at android.content.res.Resources.loadDrawable(Resources.java:1954)
at android.content.res.Resources.getDrawable(Resources.java:673)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:354)
at mypkg/mymethod(myactivity.java:100)
at mypkg/mymethod(myactivity.java:100)
at android.support.v4.app.FragmentActivity.onPostResume(FragmentActivity.java:511)
at android.support.v7.app.AppCompatActivity.onPostResume(AppCompatActivity.java:178)
at android.app.Activity.performResume(Activity.java:5341)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2104)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4929)
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:798)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:565)
at dalvik.system.NativeStart.main(Native Method)
The answer to this turned out to be buried at the bottom of this guide:
https://medium.com/#chrisbanes/appcompat-v23-2-age-of-the-vectors-91cbafa87c88#.xucjbsts0
It turns out that all you need to add this line in at the beginning of the activity that will use the resource:
static {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
}
Please make sure you are using AppCompatActivity instead Activity. If you're using AppCompat's theme, then you also need to use it's Activity.
Another solution,
in addition to AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
is to wrap your vector drawable into another drawable:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/ic_your_vector"/>
</selector>
Might be useful when you use as a drawable for a TextView (i.e. DrawableLeft)
Accepted answer is not covered all cases. It will not work on Android 4.0.3/4.1.1/4.1.2 platform with 25.x.x support library. The right way to fix problem with abc_ic_ab_back_material.xml is to override homeAsUpIndicator attribute in your theme. For example, my theme is inherited from Theme.AppCompat.Light.NoActionBar. As for value of mentioned attribute, you can use #drawable/abc_ic_ab_back_mtrl_am_alpha or your custom 'back' drawable.
private resources its treated differently at compile time and runtime..to fix I usually take the offending private resource and backport it to my app in my res files
I was using the application context when calling ContextCompat.getDrawable() which also crashes the app with Resources$NotFoundException and now the following message even though everything else was set up just fine:
If the resource you are trying to use is a vector resource, you may be
referencing it in an unsupported way. See
AppCompatDelegate.setCompatVectorFromResourcesEnabled() for more info.
All I had to do was to change to the view's Context. :)
Instead of:
ContextCompat.getdrawable()
Try using:
AppCompatDrawableManager.get().getDrawable()

_HoloActivity$HoloThemeException: You must apply Holo.Theme, Holo.Theme.Light or Holo.Theme.Light.DarkActionBar theme

I'm using HoloEverywhere-1.6.8.
I have a custom theme that is based upon Holo.Theme.
<style name="JumbleeTheme" parent="Holo.Theme">
...
</style>
I'm getting the crash below but it is only appearing for the following devices:
Galaxy Tab 10.1 P7510 10.1" 800*1280 149ppi Android#4.0
HT EVO 4G 4.3" 480*800 217ppi Android#2.3
Galaxy S2 4.3" 480*800 217ppi Android#2.3
android.support.v4.app._HoloActivity$HoloThemeException: You must
apply Holo.Theme, Holo.Theme.Light or Holo.Theme.Light.DarkActionBar
theme on the activity (SplashActivity) for using HoloEverywhere
at android.support.v4.app._HoloActivity.onInit(SourceFile:482)
at android.support.v4.app._HoloActivity.forceInit(SourceFile:223)
at org.holoeverywhere.app.Activity.onCreate(SourceFile:215)
at au.com.xandar.jumblee.AbstractAppActivity.onCreate(SourceFile:80)
at au.com.xandar.jumblee.splash.SplashActivity.onCreate(SourceFile:34)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Has anyone got any ideas on why this is only occurring for such a small subset of devices and what I can do about it?
AFAICT there is absolutely nothing wrong with either my code or with HoloEverywhere.
For some inexplicable reason those devices sometimes seem to lose the Holo.Theme attribute from the Activity's style. This causes HE to throw an Exception.
In case anyone else falls into this error this is the work around I am going with.
#Override
protected Holo onCreateConfig(Bundle savedInstanceState) {
final Holo config = super.onCreateConfig(savedInstanceState);
config.ignoreThemeCheck = true;
return config;
}
As this will cause HE not to check that a a HE theme has been defined.
Because of the way that HoloEverywhere is setup, you need to have your theme be a sub-theme (for lack of a better term) of #style/Holo.Theme

java.lang.RuntimeException Theme.Sherlock

I have put an update on google play and see this error :
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.jim2/com.jim2.SettingWidgetActivity}: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
at android.app.ActivityThread.access$500(ActivityThread.java:122)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:132)
at android.app.ActivityThread.main(ActivityThread.java:4123)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1007)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:919)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:853)
at com.actionbarsherlock.app.SherlockFragmentActivity.setContentView(SherlockFragmentActivity.java:251)
at com.jim2.SettingWidgetActivity.onCreate(SettingWidgetActivity.java:37)
at android.app.Activity.performCreate(Activity.java:4397)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
... 11 more
I don't understand why this error appear cause it's work perfectly on my devices
Anyone have an idea ?
Here is a part of my Manifest.xml
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
Thanks
Don't use android:theme="#style/Theme.Sherlock".
Use setTheme(R.style.Theme_Sherlock); inside OnCreate.
E.g.
#Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_Sherlock);
super.onCreate(savedInstanceState);
// What you want to do here
}
You can just make your style inherit from Theme.Sherlock
<style name="MyAppTheme" parent="Theme.Sherlock">
then in manifest use your theme
android:theme="#style/MyAppTheme"
You do not have to use setTheme on every page as Muz said this seem like a lot of work when there are much better solutions, would mark the above answer down but I can't !!
I agree with matt_lethargic. In my style file was:
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
My application stoped crashing after I changed it to:
<style name="AppBaseTheme" parent="Theme.Sherlock">

Tab activity seeming to die randomly loading state drawable

I have a TabActivity that seems to be dieing on a small set of phones when I add the Drawable to it. From the reports, the same tab code ran successfully at one point, but suddenly stopped during one launch(usually via pending intent)
The code thats executing in onCreate is this
spec = theTtabHost.newTabSpec(STATS_TAG).setIndicator(getText(R.string.statsTab),
res.getDrawable(R.drawable.ic_tab_stats))
The stack trace I receive is here
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.test/com.test.Main}: android.content.res.Resources$NotFoundException: File res/drawable/ic_tab_stats.xml from drawable resource ID #0x7f020013
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2737)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2753)
at android.app.ActivityThread.access$2500(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2107)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/ic_tab_stats.xml from drawable resource ID #0x7f020013
at android.content.res.Resources.loadDrawable(Resources.java:1725)
at android.content.res.Resources.getDrawable(Resources.java:590)
at com.test.Main.onCreate(Main.java:162)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2701)
... 11 more
Caused by: java.lang.NullPointerException
at android.graphics.drawable.DrawableContainer$DrawableContainerState.addChild(DrawableContainer.java:349)
at android.graphics.drawable.StateListDrawable$StateListState.addStateSet(StateListDrawable.java:265)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:796)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:737)
at android.content.res.Resources.loadDrawable(Resources.java:1722)
... 15 more
The ic_tab_stats.xml file is in drawable, and is here.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/stats"
android:state_selected="true" />
<item android:drawable="#drawable/stats_deselect" />
</selector>
The stats.png and stats_deselect.png are peers inside drawable. hdpi and ldpi do not have either file, and mdpi is empty. My app supports back to 1.5, so I used drawable instead of mdpi.
From the reports, it seems to be pretty random.
Turns out this is sort of normal behavior on Android upgrades.

Categories

Resources