ActionBarSherlock布局膨胀错误

时间:2012-09-12 10:29:14

标签: android android-layout actionbarsherlock

我在onCreateView的这一行使用ActionBarSherlock的对话框片段有一个奇怪的问题

LinearLayout root = (LinearLayout) inflater.inflate(com.example.R.layout.new_event_dialog_fragment, container, false);

这是我的ActionBarSherlock项目清单:

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>

这是我的应用目标:

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15" />

在api等级为10的模拟器上运行我的应用程序时出现此错误:

892: E/AndroidRuntime(645): FATAL EXCEPTION: main
09-12 10:00:38.892: E/AndroidRuntime(645): android.view.InflateException: Binary XML file line #26: Error inflating class android.view.View
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.createView(LayoutInflater.java:518)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
09-12 10:00:38.892: E/AndroidRuntime(645):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-12 10:00:38.892: E/AndroidRuntime(645):  at com.example.gui.fragment.dialog.NewEventDialogFragment.onCreateView(NewEventDialogFragment.java:34)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.os.Handler.handleCallback(Handler.java:587)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.os.Looper.loop(Looper.java:123)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.app.ActivityThread.main(ActivityThread.java:3683)
09-12 10:00:38.892: E/AndroidRuntime(645):  at java.lang.reflect.Method.invokeNative(Native Method)
09-12 10:00:38.892: E/AndroidRuntime(645):  at java.lang.reflect.Method.invoke(Method.java:507)
09-12 10:00:38.892: E/AndroidRuntime(645):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
09-12 10:00:38.892: E/AndroidRuntime(645):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
09-12 10:00:38.892: E/AndroidRuntime(645):  at dalvik.system.NativeStart.main(Native Method)
09-12 10:00:38.892: E/AndroidRuntime(645): Caused by: java.lang.reflect.InvocationTargetException
09-12 10:00:38.892: E/AndroidRuntime(645):  at java.lang.reflect.Constructor.constructNative(Native Method)
09-12 10:00:38.892: E/AndroidRuntime(645):  at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.LayoutInflater.createView(LayoutInflater.java:505)
09-12 10:00:38.892: E/AndroidRuntime(645):  ... 21 more
09-12 10:00:38.892: E/AndroidRuntime(645): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x2/d=0x101030a a=-1}
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.content.res.Resources.loadDrawable(Resources.java:1681)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.View.<init>(View.java:1951)
09-12 10:00:38.892: E/AndroidRuntime(645):  at android.view.View.<init>(View.java:1899)
09-12 10:00:38.892: E/AndroidRuntime(645):  ... 24 more

如果我在api level 7的模拟器上运行,我会遇到这个不同的错误:

09-12 10:15:02.035:E / AndroidRuntime(220):Uncaught h

Handler: thread main exiting due to uncaught exception
09-12 10:15:02.067: E/AndroidRuntime(220): android.view.InflateException: Binary XML file line #26: Error inflating class android.view.View
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.createView(LayoutInflater.java:513)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
09-12 10:15:02.067: E/AndroidRuntime(220):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-12 10:15:02.067: E/AndroidRuntime(220):  at com.example.gui.fragment.dialog.NewEventDialogFragment.onCreateView(NewEventDialogFragment.java:34)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:420)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.os.Handler.handleCallback(Handler.java:587)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.os.Handler.dispatchMessage(Handler.java:92)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.os.Looper.loop(Looper.java:123)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.app.ActivityThread.main(ActivityThread.java:4363)
09-12 10:15:02.067: E/AndroidRuntime(220):  at java.lang.reflect.Method.invokeNative(Native Method)
09-12 10:15:02.067: E/AndroidRuntime(220):  at java.lang.reflect.Method.invoke(Method.java:521)
09-12 10:15:02.067: E/AndroidRuntime(220):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
09-12 10:15:02.067: E/AndroidRuntime(220):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
09-12 10:15:02.067: E/AndroidRuntime(220):  at dalvik.system.NativeStart.main(Native Method)
09-12 10:15:02.067: E/AndroidRuntime(220): Caused by: java.lang.reflect.InvocationTargetException
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.View.<init>(View.java:1799)
09-12 10:15:02.067: E/AndroidRuntime(220):  at java.lang.reflect.Constructor.constructNative(Native Method)
09-12 10:15:02.067: E/AndroidRuntime(220):  at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.LayoutInflater.createView(LayoutInflater.java:500)
09-12 10:15:02.067: E/AndroidRuntime(220):  ... 21 more
09-12 10:15:02.067: E/AndroidRuntime(220): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_dropdown.xml from drawable resource ID #0x0
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.content.res.Resources.loadDrawable(Resources.java:1693)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.content.res.TypedArray.getDrawable(TypedArray.java:548)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.view.View.<init>(View.java:1850)
09-12 10:15:02.067: E/AndroidRuntime(220):  ... 25 more
09-12 10:15:02.067: E/AndroidRuntime(220): Caused by: android.content.res.Resources$NotFoundException: File res/drawable/btn_dropdown.xml from xml type drawable resource ID #0x0
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1920)
09-12 10:15:02.067: E/AndroidRuntime(220):  at android.content.res.Resources.loadDrawable(Resources.java:1688)
09-12 10:15:02.067: E/AndroidRuntime(220):  ... 27 more

我的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"


    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:orientation="vertical">
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:padding="8dp">
        <TextView android:id="@+id/textView1" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:paddingRight="5dp"
            android:text="@string/event_name" android:textAppearance="?android:attr/textAppearanceSmall" />
        <EditText android:id="@+id/editText1" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:ems="10" android:inputType="textCapWords">
            <requestFocus />
        </EditText>
    </LinearLayout>
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content" android:padding="8dp">
        <TextView android:id="@+id/textView2" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_gravity="center_vertical"
            android:gravity="center_vertical" android:paddingRight="5dp"
            android:text="@string/currency" android:textAppearance="?android:attr/textAppearanceSmall" />
        <Spinner android:id="@+id/spinner1" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_gravity="center_vertical"
            android:layout_weight="1" />
    </LinearLayout>
    <View android:id="@+id/horizontal_divider_login"
        android:layout_width="match_parent" android:layout_height="1dp"
        android:layout_marginLeft="4dp" android:layout_marginRight="4dp"
        android:layout_weight="0.35" android:background="?android:attr/dividerVertical"
        android:orientation="horizontal" />
    <LinearLayout android:layout_width="match_parent"
        android:layout_height="48dp" android:orientation="horizontal">
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="0.5"
            android:gravity="center" android:orientation="vertical">
            <Button android:id="@+id/btn_abort"
                style="@android:style/Widget.Holo.Button.Borderless.Small"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:text="@android:string/cancel" android:textColor="?android:attr/textColorPrimary" />
        </LinearLayout>
        <LinearLayout android:id="@+id/vertical_divider"
            android:layout_width="1dip" android:layout_height="match_parent"
            android:layout_marginBottom="4dp" android:layout_marginTop="4dp"
            android:background="?android:attr/dividerVertical" />
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="0.5"
            android:gravity="center" android:orientation="vertical">
            <Button android:id="@+id/btn_ok"
                style="@android:style/Widget.Holo.Button.Borderless.Small"
                android:layout_width="match_parent" android:layout_height="wrap_content"
                android:layout_weight="0.5" android:text="@android:string/ok"
                android:textColor="?android:attr/textColorPrimary" />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

在这两种情况下,这似乎是一个资源错误(我考虑spinner的res),但我无法解决。我尝试改变api目标,完全干净..但没有。感谢

PS:在我的真实设备(4.0.4)或模拟器(4.1.1)上运行都可以正常运行

1 个答案:

答案 0 :(得分:3)

引发异常,因为一个或多个Resources不是Drawable。 尝试从xml中删除它

android:background="?android:attr/dividerVertical"