我在我的应用中有这个来源:
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
setTheme(getHoneycombStyle());
ActionBar actionBar = getActionBar();
if (actionBar != null) {
actionBar.setCustomView(R.layout.ACTION_BAR);
}
}
}
它在Honeycomb,Android 2.1,2.2和2.3中运行良好,但是,它在Android 1.6中不起作用。虽然我已经检查了SDK版本,但应用程序会返回此异常:
08-31 18:23:33.063: ERROR/AndroidRuntime(3262): Uncaught handler: thread main exiting due to uncaught exception
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): java.lang.VerifyError: com.eldan.introducing.activity.IBBaseCompActivity
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at java.lang.Class.newInstanceImpl(Native Method)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at java.lang.Class.newInstance(Class.java:1472)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.ActivityThread.startActivityNow(ActivityThread.java:2242)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:631)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.widget.TabHost.setCurrentTab(TabHost.java:317)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:127)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:346)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.View.performClick(View.java:2344)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.View.onTouchEvent(View.java:4133)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.View.dispatchTouchEvent(View.java:3672)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:850)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:882)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1712)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1202)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.Activity.dispatchTouchEvent(Activity.java:1987)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1696)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.view.ViewRoot.handleMessage(ViewRoot.java:1658)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.os.Handler.dispatchMessage(Handler.java:99)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.os.Looper.loop(Looper.java:123)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at android.app.ActivityThread.main(ActivityThread.java:4203)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at java.lang.reflect.Method.invokeNative(Native Method)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at java.lang.reflect.Method.invoke(Method.java:521)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
08-31 18:23:33.083: ERROR/AndroidRuntime(3262): at dalvik.system.NativeStart.main(Native Method)
听起来编译器检测到ActionBar
方法中的onCreate
来源,而Android 1.6不支持它。但我不太确定如何解决这个问题。
答案 0 :(得分:3)
您无法在加载到旧版Android的VM中的代码中引用较新版本的Android中的类或方法。
您有两个主要选择:
将ActionBar
代码隔离到单独的实用程序类中,并且仅在使用Honeycomb时使用该类,由android.os.Build
确定。 Here is a sample project通过隔离getActionView()
类中的getActionView()
调用,演示如何使用HoneycombHelper
将自定义布局放入操作栏,该操作栏适用于Honeycomb和旧版本仅用于Honeycomb。
使用ActionBarSherlock访问操作栏。它将为您提供Honeycomb上的原生操作栏,以及适用于旧版Android的工作栏。