App crash in Android M

2019-03-30 07:28发布

问题:

My app always work fine, but now is crashing in the new Android M preview I think that the problem is with the ActionBarSherlock. Someone have the same problem or know how can I fix it?

This is the error:

07-31 10:41:59.435: E/AndroidRuntime(4239): FATAL EXCEPTION: main
07-31 10:41:59.435: E/AndroidRuntime(4239): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.messaging.android/com.myapp.messaging.android.holo.messagelist.MainActivity}: java.lang.RuntimeException: java.lang.IllegalAccessException: java.lang.Class<org.holoeverywhere.addon.AddonSherlock$HoloActionBarSherlockNative> is not accessible from java.lang.Class<com.actionbarsherlock.ActionBarSherlock>
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2477)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread.-wrap11(ActivityThread.java)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1345)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.os.Handler.dispatchMessage(Handler.java:102)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.os.Looper.loop(Looper.java:148)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread.main(ActivityThread.java:5415)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at java.lang.reflect.Method.invoke(Native Method)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:725)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:615)
07-31 10:41:59.435: E/AndroidRuntime(4239): Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: java.lang.Class<org.holoeverywhere.addon.AddonSherlock$HoloActionBarSherlockNative> is not accessible from java.lang.Class<com.actionbarsherlock.ActionBarSherlock>
07-31 10:41:59.435: E/AndroidRuntime(4239):     at com.actionbarsherlock.ActionBarSherlock.wrap(ActionBarSherlock.java:240)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at org.holoeverywhere.addon.AddonSherlock$AddonSherlockA.getSherlock(AddonSherlock.java:53)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at org.holoeverywhere.addon.AddonSherlock$AddonSherlockA.installDecorView(AddonSherlock.java:60)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.support.v4.app._HoloActivity$1.action(_HoloActivity.java:587)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.support.v4.app._HoloActivity$1.action(_HoloActivity.java:1)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at org.holoeverywhere.addon.IAddonBasicAttacher.performAddonAction(IAddonBasicAttacher.java:167)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at org.holoeverywhere.app.Activity.performAddonAction(Activity.java:497)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.support.v4.app._HoloActivity.requestDecorView(_HoloActivity.java:584)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.support.v4.app._HoloActivity.setContentView(_HoloActivity.java:604)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at com.myapp.messaging.android.holo.messagelist.MainActivity.onCreate(MainActivity.java:120)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.Activity.performCreate(Activity.java:6162)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2370)
07-31 10:41:59.435: E/AndroidRuntime(4239):     ... 9 more
07-31 10:41:59.435: E/AndroidRuntime(4239): Caused by: java.lang.IllegalAccessException: java.lang.Class<org.holoeverywhere.addon.AddonSherlock$HoloActionBarSherlockNative> is not accessible from java.lang.Class<com.actionbarsherlock.ActionBarSherlock>
07-31 10:41:59.435: E/AndroidRuntime(4239):     at java.lang.reflect.Constructor.newInstance(Native Method)
07-31 10:41:59.435: E/AndroidRuntime(4239):     at com.actionbarsherlock.ActionBarSherlock.wrap(ActionBarSherlock.java:232)
07-31 10:41:59.435: E/AndroidRuntime(4239):     ... 21 more

回答1:

I faced the exactly same issue today and fortunately I was able to fix it. This fix has to be done in actionbar sherlock library code. So you need to add actionbarsherlock as library project.

Make the following change in ActionBarSherlock.java

ctor.setAccessible(true);

add above line just above return ctor.newInstance(activity, flag); (line no 230 in public static ActionBarSherlock wrap(Activity activity, int flags){} method.

Similarly do following change in LayoutInflater.java

constructor.setAccessible(true); 

add this just above final View view = constructor.newInstance(args); (line no.352) in public View _createView(String name, String prefix, AttributeSet attrs){}

Note: I am using ActionBarSherlock 4.3.0