NPE同时在老Androids上充气ActionBarSherlock

时间:2014-01-08 23:08:25

标签: java android actionbarsherlock

我正在使用ActionBarSherlock并遇到可怕的问题:

01-08 22:16:05.803: E/AndroidRuntime(432): java.lang.RuntimeException: Unable to start activity ComponentInfo{ar.android.app.glarm/ar.android.app.glarm.gui.GLarmMain}: android.view.InflateException: Binary XML file line #32: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
[CUT]
01-08 22:16:05.803: E/AndroidRuntime(432): Caused by: android.view.InflateException: Binary XML file line #32: Error inflating class com.actionbarsherlock.internal.widget.ActionBarView
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.createView(LayoutInflater.java:596)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:671)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:727)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:1010)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:902)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:855)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.ActionBarSherlock.setContentView(ActionBarSherlock.java:672)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.app.SherlockListActivity.setContentView(SherlockListActivity.java:239)
01-08 22:16:05.803: E/AndroidRuntime(432):  at ar.android.app.glarm.gui.GLarmMain.onCreate(GLarmMain.java:117)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
01-08 22:16:05.803: E/AndroidRuntime(432):  ... 11 more
01-08 22:16:05.803: E/AndroidRuntime(432): Caused by: java.lang.reflect.InvocationTargetException
01-08 22:16:05.803: E/AndroidRuntime(432):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-08 22:16:05.803: E/AndroidRuntime(432):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-08 22:16:05.803: E/AndroidRuntime(432):  at android.view.LayoutInflater.createView(LayoutInflater.java:576)
01-08 22:16:05.803: E/AndroidRuntime(432):  ... 25 more
01-08 22:16:05.803: E/AndroidRuntime(432): Caused by: java.lang.NullPointerException
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.internal.widget.ActionBarView$HomeView.setUp(ActionBarView.java:1219)
01-08 22:16:05.803: E/AndroidRuntime(432):  at com.actionbarsherlock.internal.widget.ActionBarView.<init>(ActionBarView.java:231)
01-08 22:16:05.803: E/AndroidRuntime(432):  ... 28 more

我的应用程序中没有任何样式,因为我的应用程序直接使用Theme.Sherlock。 我的ABS版本是最后一个4.4.0,我试图在API 11模拟器中运行我的应用程序(API 8导致相同的结果)。 API 18工作正常。

在Eclipse中进行一些调试后,看起来以下内容返回两个空视图(ActionBarView.java):

@Override
protected void onFinishInflate() {
    mUpView = findViewById(R.id.abs__up);
    mIconView = (ImageView) findViewById(R.id.abs__home);
}

当然后来的电话正在返回NPE。看起来我的LogCat中也有一些警告:

01-08 22:54:20.093: I/dalvikvm(626): Could not find method com.actionbarsherlock.internal.nineoldandroids.widget.NineFrameLayout.onHoverEvent, referenced from method com.actionbarsherlock.internal.widget.ActionBarContainer.onHoverEvent
01-08 22:54:20.093: W/dalvikvm(626): VFY: unable to resolve virtual method 8116: Lcom/actionbarsherlock/internal/nineoldandroids/widget/NineFrameLayout;.onHoverEvent (Landroid/view/MotionEvent;)Z
01-08 22:54:20.093: D/dalvikvm(626): VFY: replacing opcode 0x6f at 0x0000
01-08 22:54:49.864: I/dalvikvm(626): Could not find method com.actionbarsherlock.internal.widget.ActionBarView$HomeView.onHoverEvent, referenced from method com.actionbarsherlock.internal.widget.ActionBarView$HomeView.dispatchHoverEvent
01-08 22:54:49.864: W/dalvikvm(626): VFY: unable to resolve virtual method 8980: Lcom/actionbarsherlock/internal/widget/ActionBarView$HomeView;.onHoverEvent (Landroid/view/MotionEvent;)Z
01-08 22:54:49.864: D/dalvikvm(626): VFY: replacing opcode 0x6e at 0x0000
01-08 22:54:49.864: I/dalvikvm(626): Could not find method android.widget.FrameLayout.onPopulateAccessibilityEvent, referenced from method com.actionbarsherlock.internal.widget.ActionBarView$HomeView.onPopulateAccessibilityEvent
01-08 22:54:49.864: W/dalvikvm(626): VFY: unable to resolve virtual method 5731: Landroid/widget/FrameLayout;.onPopulateAccessibilityEvent (Landroid/view/accessibility/AccessibilityEvent;)V
01-08 22:54:49.864: D/dalvikvm(626): VFY: replacing opcode 0x6f at 0x0006

我的问题是什么?

PS:我使用Eclipse + Maven并包含android-v4支持19.0.1和NineOldAndroids 2.4.0。


修改

经过一些其他调试后,看起来ActionBarSherlock和R.txt(Maven生成的目标/文件夹)中生成的资源编号不一样。 检查调试器,我有:

R.txt -> int layout abs__action_bar_home 0x7f030000 | Debug -> same
R.txt -> int id abs__up 0x7f07000b | Debug -> ox7f04000b
R.txt -> int id abs__home 0x7f07000a | Debug -> 0x7f04000a

更新

导入apklib时看起来有问题... R编译出错了。 解决方法是删除与abs __ * 1的id不对齐的自定义资源并弄乱编号。例如,我做了以下事情:

  • 我检查了ActionBarSherlock失败的地方,对我来说,这是在加载资源R.id.abs__up时。
  • 我从R.java文件中获取了资源编号并记下来(0x7f07XXXX);
  • 我删除了0x7f07XXXX之前的所有资源,清理了项目,重新生成了R.我想将R.id.abs__up对齐到它的apklib编号(0x7f04000b)。我不得不从我的字符串xml中删除三个文件夹(anim /,xml /,raw /)和三个实际资源。
  • 现在R.id.abs__up在我编译的R.java中有正确的数字。

参见讨论here

0 个答案:

没有答案