6

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

jaumard
  • 8,202
  • 3
  • 40
  • 63

3 Answers3

10

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
}
piotrek1543
  • 19,130
  • 7
  • 81
  • 94
Muz
  • 5,866
  • 3
  • 47
  • 65
  • 1
    Normally it's the same like i do isn't it ? – jaumard Oct 13 '12 at 13:58
  • @jaumard Yes, you can do that too, but it isn't necessary. You do need to put the setTheme() in the OnCreate, or it will crash. – Muz Oct 13 '12 at 15:42
  • Thanks but error was fix i don't know how... maybe a compilation error with eclipse. I don't want to use setTheme on all my activities if i can put only once in my manifest. – jaumard Oct 17 '12 at 06:55
  • 1
    It's a requirement from the `ActionBarSherlock`. Usually I make a BaseActivity for all code I want to copy onto all other activities, and then extend all the other activities from that BaseActivity. So you could write it once in whatever your base activity is. – Muz Oct 17 '12 at 07:58
  • 5
    From official ActionbarSherlock documentation: "The themes should be defined in your manifest for the entire application or on a per-activity basis. You may also define the theme in the code of each activity before calling super.onCreate(Bundle)". http://actionbarsherlock.com/theming.html – AndacAydin Mar 07 '13 at 20:36
  • 1
    @JakeWharton Hey, thanks for commenting, Jake! Would you mind supplying/linking an example that shows the right way to do it? Because a lot of us are stuck on this, and this is the best hack that's worked consistently so far. – Muz Aug 02 '13 at 03:27
2

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

matt_lethargic
  • 2,706
  • 1
  • 18
  • 33
2

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">
Ruslan Mansurov
  • 1,281
  • 16
  • 23