2012-09-12 146 views
2

我使用ActionBarSherlock在這一行onCreateViewActionBarSherlock佈局充氣錯誤

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級7仿真器上運行我得到這個不同的錯誤:

10月9日至一十二日:15:02.035:E/AndroidRuntime(220):未捕獲ħ

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> 

這似乎是在兩種情況下的資源錯誤(我想微調的res),但我無法解析。我嘗試改變API目標,完全乾淨..但沒有。由於

PS:我的真實設備(4.0.4)上或在模擬器中運行(4.1.1)全是因爲一個或多個資源是不是可繪製工作正常

+0

發佈您的佈局! – Wayne

+0

對不起,我忘了它,加入 –

回答

3

那exeption拋出。 嘗試從您的xml中刪除此內容

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

非常感謝,它的工作原理! –

+0

更新:問題不解決與仿真器和api_7。錯誤是不同的(見主文章) –

+0

我已經測試了模擬器API級別7,並沒有發生錯誤。有2行'android:background =「?android:attr/dividerVertical」',你把它們都刪除了嗎? – Wayne