我没有明确的理由得到这个奇怪的错误。我只在使用EditText时得到它,当我用TextView替换EditText时,不会发生错误。我在另一个活动中使用EditText视图就好了,除了这个。这是我的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/imgLayout"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_marginBottom="30dp"
android:layout_weight="0.45"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:id="@+id/streetImg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:background="@color/blacktrans">
<TextView
android:id="@+id/locationName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="14sp"
android:textStyle="bold" />
<TextView
android:id="@+id/address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/locationName"
android:layout_marginLeft="10dp"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/divider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="@id/address"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:background="@drawable/divider" />
<TextView
android:id="@+id/opentxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/divider"
android:layout_marginLeft="20dp"
android:layout_marginTop="5dp"
android:text="Open"
android:textColor="@android:color/white"
android:textSize="12sp" />
<TextView
android:id="@+id/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/opentxt"
android:layout_marginLeft="20dp"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/costtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/divider"
android:layout_centerHorizontal="true"
android:layout_marginTop="5dp"
android:text="Cost"
android:textColor="@android:color/white"
android:textSize="12sp" />
<LinearLayout
android:id="@+id/costlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/costtxt"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<TextView
android:id="@+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="/min"
android:textColor="@android:color/white"
android:textSize="12sp" />
</LinearLayout>
<TextView
android:id="@+id/distancetxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/divider"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:text="Distance"
android:textColor="@android:color/white"
android:textSize="12sp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/distancetxt"
android:layout_marginRight="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/distancetxt"
android:textColor="@color/colorPrimary"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" miles"
android:textColor="@android:color/white"
android:textSize="12sp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/controLayout"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_centerHorizontal="true"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:layout_weight="0.55"
android:gravity="center_horizontal"
android:paddingLeft="@dimen/view_left_margin"
android:paddingRight="@dimen/view_right_margin"
android:paddingTop="@dimen/view_top_margin">
<ImageView
android:id="@+id/dateIcn"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/margin"
android:src="@drawable/srch_cal" />
<EditText
android:id="@+id/dateEdit"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_toRightOf="@+id/dateIcn"
android:backgroundTint="@color/gray"
android:focusable="false"
android:hint="Date"
android:textColor="@android:color/darker_gray"
android:textColorHint="@color/gray"
android:textSize="16sp" />
<ImageView
android:id="@+id/timeIcn"
android:layout_width="27dp"
android:layout_height="27dp"
android:layout_toLeftOf="@+id/timeEdit"
android:src="@drawable/srch_clock" />
<EditText
android:id="@+id/timeEdit"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/margin"
android:backgroundTint="@color/gray"
android:focusable="false"
android:hint="Time"
android:textColor="@android:color/darker_gray"
android:textColorHint="@color/gray"
android:textSize="16sp" />
<TextView
android:id="@+id/rsrvfor"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/timeEdit"
android:layout_marginLeft="16dp"
android:layout_marginTop="15dp"
android:text="Reserve for: "
android:textSize="16sp" />
<TextView
android:id="@+id/seekval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timeEdit"
android:layout_marginLeft="5dp"
android:layout_marginTop="13dp"
android:layout_toRightOf="@+id/rsrvfor"
android:text="10"
android:textColor="@color/colorAccent"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/timeEdit"
android:layout_marginTop="14dp"
android:layout_toRightOf="@+id/seekval"
android:text=" min"
android:textColor="@color/colorAccent"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/min120"
android:layout_width="wrap_content"
android:layout_height="14dp"
android:layout_alignParentRight="true"
android:layout_below="@+id/timeEdit"
android:layout_marginRight="16dp"
android:layout_marginTop="15dp"
android:text="120 min"
android:textSize="12sp" />
<SeekBar
android:id="@+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/timeEdit"
android:layout_marginTop="21dp"
android:max="110" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/seekbar"
android:gravity="center_horizontal"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="$"
android:textColor="@color/colorAccent"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/price"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5.0"
android:textColor="@color/colorAccent"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="@+id/pay"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="40dp"
android:layout_marginLeft="@dimen/margin"
android:layout_marginRight="@dimen/margin"
android:background="@color/colorPrimary"
android:text="Pay and Reserve"
android:textAllCaps="false"
android:textColor="@android:color/white" />
</RelativeLayout>
这是堆栈跟踪
07-03 17:42:40.148 26088-26088/com.ridecell.app.ridecell E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.ridecell.app.ridecell, PID: 26088
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ridecell.app.ridecell/com.ridecell.app.ridecell.Activities.SpotInfoActivity}: android.view.InflateException: Binary XML file line #192: Error inflating class EditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2693)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.view.InflateException: Binary XML file line #192: Error inflating class EditText
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.ridecell.app.ridecell.Activities.SpotInfoActivity.onCreate(SpotInfoActivity.java:61)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-v21/abc_edit_text_material.xml from drawable resource ID #0x7f020012
at android.content.res.Resources.loadDrawableForCookie(Resources.java:3735)
at android.content.res.Resources.loadDrawable(Resources.java:3603)
at android.content.res.TypedArray.getDrawable(TypedArray.java:762)
at android.view.View.<init>(View.java:3970)
at android.widget.TextView.<init>(TextView.java:987)
at android.widget.EditText.<init>(EditText.java:74)
at android.widget.EditText.<init>(EditText.java:70)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:60)
at android.support.v7.widget.AppCompatEditText.<init>(AppCompatEditText.java:56)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:112)
at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:1008)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:1067)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:732)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:821)
at android.view.LayoutInflater.inflate(LayoutInflater.java:511)
at android.view.LayoutInflater.inflate(LayoutInflater.java:415)
at android.view.LayoutInflater.inflate(LayoutInflater.java:366)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:280)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.ridecell.app.ridecell.Activities.SpotInfoActivity.onCreate(SpotInfoActivity.java:61)
at android.app.Activity.performCreate(Activity.java:6288)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2760)
at android.app.ActivityThread.access$900(ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1448)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5944)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #24: <nine-patch> requires a valid 9-patch source image
at android.graphics.drawable.NinePatchDrawable.updateStateFromTypedArray(NinePatchDrawable.java:445)
at android.graphics.drawable.NinePatchDrawable.inflate(NinePatchDrawable.java:401)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:185)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
at android.graphics.drawable.InsetDrawable.inflate(InsetDrawable.java:105)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1150)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:1063)
at android.content.res.R