我有两个活动,其中第一个有一个按钮,点击时应该转到下一个活动。但是当点击时我得到以下错误。我有一个ImageView,其背景是三角形的。当我删除imageview它工作正常。
以下是错误:
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: FATAL EXCEPTION: main
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jobinsabu.destination/com.example.jobinsabu.destination.PickDrop}:android.view.InflateException: Binary XML file line #46: Error inflating class ImageView
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: Caused by:android.view.InflateException: Binary XML file line #46: Error inflating class ImageView
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: Caused by: android.content.res.Resources$NotFoundException: File res/drawable/triange_shape.xml from drawable resource ID #0x7f0200ce
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.content.res.Resources.loadDrawable(Resources.java:2842)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at com.example.jobinsabu.destination.PickDrop.onCreate(PickDrop.java:14)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #3: invalid drawable tag vector
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:917)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.graphics.drawable.Drawable.createFromXml(Drawable.java:858)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:58)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:54)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:95)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:256)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at com.example.jobinsabu.destination.PickDrop.onCreate(PickDrop.java:14)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.Activity.performCreate (Activity.java:5326)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2215)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2306)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.ActivityThread.access$700(ActivityThread.java:153)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1286)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:99)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:176)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5302)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:511)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
02-25 12:54:20.469 14973-14973/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
pick_drop.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:background="@drawable/bg0"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#70000000"
android:id="@+id/toolbar2"
/>
<RelativeLayout
android:id="@+id/relative3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#40000000"
android:layout_marginTop="50dp"
android:layout_alignParentBottom="true"
android:layout_below="@+id/toolbar2"
android:visibility="visible">
<Button
android:id="@+id/pick"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"
android:background="@drawable/circle_shape"
android:text="Pick"
android:textColor="#ffffff" />
<Button
android:id="@+id/drop"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_marginRight="5dp"
android:background="@drawable/circle_shape"
android:text="Drop"
android:textColor="#ffffff" />
<ImageView
android:layout_width="40dp"
android:layout_height="23dp"
android:id="@+id/triangle1"
android:background="@drawable/triange_shape"
android:layout_marginLeft="35dp"
android:layout_below="@+id/pick"></ImageView>
<ImageView
android:layout_width="40dp"
android:layout_height="23dp"
android:id="@+id/triangle"
android:background="@drawable/triange_shape"
android:layout_marginLeft="28dp"
android:layout_below="@+id/drop"
android:layout_alignLeft="@+id/drop"
android:layout_alignStart="@+id/drop"
android:layout_marginStart="28dp"></ImageView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="2dp"
android:layout_marginRight="3dp"
android:background="@drawable/layout_border"
android:layout_centerVertical="true"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Place"
android:id="@+id/place"
android:textSize="20sp"
android:textAllCaps="true"
android:background="#9000"
android:paddingTop="3dp"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginRight="2dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textColor="#F50057"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Pick me here"
android:textColorHint="#fff"
android:textColor="#ffffff"
android:background="#4000"
android:id="@+id/placedetails"
android:layout_below="@+id/place"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Date"
android:layout_below="@+id/placedetails"
android:id="@+id/pickup_date"
android:textSize="20sp"
android:textColor="#F50057"
android:gravity="center"
android:background="#9000"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginRight="2dp"
android:textAllCaps="true"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Time"
android:textAllCaps="true"
android:id="@+id/pickup_time"
android:textSize="20sp"
android:gravity="center"
android:background="#9000"
android:layout_marginLeft="2dp"
android:layout_marginTop="2dp"
android:layout_marginRight="2dp"
android:textColor="#F50057"
/>
<EditText
android:id="@+id/materialedittext1"
android:layout_width="match_parent"
android:layout_below="@+id/pickup_time"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="21dp"
android:hint="Enter the date"
android:textColor="#ffffff"
android:textColorHint="#fff"
/>
</LinearLayout>
</RelativeLayout>
<Button
android:id="@+id/enter"
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@drawable/button_syle"
android:text="GET ME THERE"
android:textColor="#E0E0E0"
android:typeface="sans"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/pick"
android:layout_alignStart="@+id/pick" />
</RelativeLayout>
triangle_shape(drawable).xml(设置为图像视图的背景)
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportHeight="100"
android:viewportWidth="100">
<group android:name="triableGroup">
<path
android:name="triangle"
android:fillColor="#FF5722"
android:pathData="m 50,0 l 50,50 -100,0 z"
android:strokeColor="#FF5722"
/>
</group>
</vector>
PickDrop的Java代码: 公共类PickDrop扩展了AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pick_drop);
}
}
triangle_shape(编辑).XML:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<rotate
android:fromDegrees="-45"
android:toDegrees="45"
android:pivotX="220%"
android:pivotY="70%" >
<shape
android:shape="rectangle" >
<stroke android:color="#fff" android:width="1dp"/>
<solid
android:color="#fff" />
</shape>
</rotate>
</item>
</layer-list>
答案 0 :(得分:0)
请检查你的xml文件是否在drawable文件夹中?
资源$ NotFoundException:来自drawable的文件res / drawable / triange_shape.xml
答案 1 :(得分:0)
尝试使用Shape标签创建三角形。
答案 2 :(得分:0)
以下链接可以帮助您。使用triangleType centerTop并根据您的要求自定义大小和颜色。 https://gist.github.com/rsicarelli/770863bc2833b0eab991