当我在 android 版本 <= 2.3.x 的模拟器上部署我的应用程序时出现此错误。在最高版本上一切正常:
05-22 09:33:53.641: E/AndroidRuntime(740): FATAL EXCEPTION: main
05-22 09:33:53.641: E/AndroidRuntime(740): android.view.InflateException: Binary XML file line #18: Error inflating class android.widget.QuickContactBadge
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
05-22 09:33:53.641: E/AndroidRuntime(740): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.ui.MyFragment.onCreateView(MyFragment.java:120)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:871)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1083)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:635)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1431)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:431)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.controls.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:163)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.view.ViewPager.populate(ViewPager.java:895)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:469)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:441)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:422)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.controls.MyPager.setCurrentItem(MyPager.java:207)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.controls.MyPager.showLast(MyPager.java:212)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.ui.MyActivity$LoadUnreadMessagesAsyncTask.onPostExecute(MyActivity.java:377)
05-22 09:33:53.641: E/AndroidRuntime(740): at myapp.ui.MyActivity$LoadUnreadMessagesAsyncTask.onPostExecute(MyActivity.java:1)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.os.AsyncTask.finish(AsyncTask.java:417)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.os.AsyncTask.access$300(AsyncTask.java:127)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.os.Handler.dispatchMessage(Handler.java:99)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.os.Looper.loop(Looper.java:130)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-22 09:33:53.641: E/AndroidRuntime(740): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 09:33:53.641: E/AndroidRuntime(740): at java.lang.reflect.Method.invoke(Method.java:507)
05-22 09:33:53.641: E/AndroidRuntime(740): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
05-22 09:33:53.641: E/AndroidRuntime(740): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
05-22 09:33:53.641: E/AndroidRuntime(740): at dalvik.system.NativeStart.main(Native Method)
05-22 09:33:53.641: E/AndroidRuntime(740): Caused by: java.lang.reflect.InvocationTargetException
05-22 09:33:53.641: E/AndroidRuntime(740): at java.lang.reflect.Constructor.constructNative(Native Method)
05-22 09:33:53.641: E/AndroidRuntime(740): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
05-22 09:33:53.641: E/AndroidRuntime(740): ... 34 more
05-22 09:33:53.641: E/AndroidRuntime(740): Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f0200bd a=-1 r=0x7f0200bd}
05-22 09:33:53.641: E/AndroidRuntime(740): at android.content.res.Resources.loadDrawable(Resources.java:1681)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.view.View.<init>(View.java:1951)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.widget.ImageView.<init>(ImageView.java:112)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.widget.QuickContactBadge.<init>(QuickContactBadge.java:92)
05-22 09:33:53.641: E/AndroidRuntime(740): at android.widget.QuickContactBadge.<init>(QuickContactBadge.java:88)
05-22 09:33:53.641: E/AndroidRuntime(740): ... 37 more
此错误涉及 MyFragment 第 120 行:
@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
...
120: View v = inflater.inflate(R.layout.my_fragment_layout, null);
}
这是我的片段布局:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="UselessParent" >
<LinearLayout
android:id="@+id/myMessageMainlayout"
android:layout_width="@dimen/my_pager_width"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:background="#FFFFFF"
android:orientation="vertical" >
<RelativeLayout android:id="@+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="left" >
<QuickContactBadge android:layout_alignParentLeft="true" android:layout_centerVertical="true"
android:id="@+id/contactBadge"
android:layout_gravity="center"
android:background="@drawable/quickcontact_badge_small"
android:clickable="false"
android:scaleType="fitCenter"
android:src="@drawable/ic_contact_picture" />
<TextView android:layout_alignParentTop="true" android:layout_marginTop="5dp"
android:id="@+id/fromTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_toLeftOf="@+id/imgbtn__overflow" android:layout_toRightOf="@+id/contactBadge" android:autoLink="phone" android:ellipsize="end" android:fontFamily="sans-serif-light" android:gravity="center_vertical" android:maxLines="2" android:paddingBottom="2dp" android:text="Text Here" android:textAppearance="?android:attr/textAppearanceLarge" android:textColorLink="?android:attr/textColorPrimaryDisableOnly" tools:ignore="HardcodedText"/>
<TextView android:layout_alignLeft="@+id/fromTextView" android:layout_below="@+id/fromTextView"
android:id="@+id/timestampTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.5"
android:fontFamily="sans-serif-light"
android:paddingTop="2dp"
android:text="Timestamp here"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorPrimaryDisableOnly"
tools:ignore="HardcodedText" />
<ImageButton android:id="@+id/imgbtn__overflow" style="@style/Widget.Sherlock.ActionButton" android:layout_width="30dp" android:layout_height="30dp" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:layout_marginTop="4dp" android:src="@drawable/abs__ic_menu_moreoverflow_normal_holo_light"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="#FFA9CC8F" android:orientation="vertical">
</LinearLayout>
<ScrollView
android:id="@+id/contentMessage"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:fillViewport="true"
android:padding="8dp" >
<TextView
android:id="@+id/messageTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="all"
android:fontFamily="sans-serif-light"
android:gravity="top"
android:text="Text here"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimaryDisableOnly"
android:textColorLink="?android:attr/textColorPrimaryDisableOnly"
tools:ignore="HardcodedText" />
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:background="#FFA9CC8F" android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:id="@+id/answerbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingRight="4dp" >
<EditText
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="09" android:autoText="true" android:ems="10" android:fontFamily="sans-serif-light" android:gravity="top" android:hint="@string/text_hint" android:imeOptions="actionDone|flagNoEnterAction" android:inputType="textShortMessage|textMultiLine|textAutoCorrect|textCapSentences" android:maxLines="4" android:minLines="2" android:nextFocusRight="@+id/send_" android:shadowColor="#000000" android:shadowDy="0.5" android:shadowRadius="0.5">
<requestFocus />
</EditText>
<ImageButton
android:id="@+id/imgbtn_send"
style="@style/Widget.Sherlock.ActionButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0.5" android:src="@android:drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="@+id/contentMms"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:visibility="gone" >
<TextView
android:id="@+id/mmsSubjectTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="Mms subject here"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorPrimaryDisableOnly"
android:textColorLink="?android:attr/textColorPrimaryDisableOnly"
tools:ignore="HardcodedText" />
<Button
android:id="@+id/viewMmsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:minWidth="140dp"
android:text="@string/button_view_mms" />
</LinearLayout>
<LinearLayout
android:id="@+id/contentPrivacy"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:paddingBottom="12dp"
android:paddingTop="12dp"
android:visibility="gone" >
<ImageButton
android:id="@+id/viewButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/button_view"
android:padding="8dp"
android:src="@android:drawable/ic_menu_view" />
</LinearLayout>
<LinearLayout
android:id="@+id/buttonPanel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:dividerPadding="0dip"
android:orientation="vertical"
android:showDividers="beginning" >
<ViewSwitcher
android:id="@+id/buttonViewSwitcher"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inAnimation="@android:anim/fade_in"
android:outAnimation="@android:anim/fade_out" >
<LinearLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="@+id/btn__close"
style="@style/Widget.Sherlock.ActionButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-light"
android:text="@string/button_close" />
<Button
android:id="@+id/btn__call"
style="@style/Widget.Sherlock.ActionButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-light"
android:text="@string/button_call" />
<Button android:id="@+id/btn__open" style="@style/Widget.Sherlock.ActionButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:fontFamily="sans-serif-light" android:text="@string/open_"/>
</LinearLayout>
<RelativeLayout
android:id="@+id/UnlockButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<include layout="@layout/unlock_button" />
</RelativeLayout>
</ViewSwitcher>
</LinearLayout>
</LinearLayout>
</FrameLayout>
布局错误与我打开 QuickContactBadge xml 标记的第 18 行有关。这怎么可能?我没有自定义样式和自定义视图。谢谢