简体   繁体   English

添加ImageView时应用崩溃

[英]App crashes when adding an ImageView

This is my xml. 这是我的xml。 The imageview1 works fine, the problem comes when i add the second imageview. imageview1工作正常,当我添加第二个imageview时出现问题。 I did a little research and found something about the problem having to do with the @id+/ but i didnt really understood. 我做了一些研究,发现了与@ id + /有关的问题,但我并没有真正理解。 Can someones tell what's wrong? 有人能说出什么问题吗?

<RelativeLayout 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" >

<Button
    android:id="@+id/button3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:enabled="false"
    android:text="@string/next"
    android:textSize="30sp" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_toLeftOf="@+id/button3"
    android:enabled="false"
    android:text="@string/check"
    android:textSize="30sp" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/button3"
    android:text="@string/mensaje"
    android:textSize="35sp" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/textView2"
    android:layout_marginTop="135dp"
    android:gravity="center"
    android:text="@string/pais"
    android:textSize="35sp" />

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:ems="10"
    android:inputType="text" >

    <requestFocus />
</EditText>

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="200dp"
    android:layout_height="100dp"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:src="@drawable/canada" />

<TextView
    android:id="@+id/textView3"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button2"
    android:layout_alignBottom="@+id/button2"
    android:layout_alignParentLeft="true"
    android:text="TextView"
    android:textSize="25sp" />

<ImageView
    android:id="@+id/imageView2"
    android:layout_width="40dp"
    android:layout_height="40dp"
    android:layout_alignTop="@+id/editText1"
    android:layout_toRightOf="@+id/editText1"
    android:src="@drawable/paloma" />

</RelativeLayout>

You don't have an end tag for your RelativeLayout . 您的RelativeLayout没有结束标记。 Just put this at the bottom: 只需将其放在底部:

</RelativeLayout>

Also, have you made sure that the drawable that you're putting on the ImageView exists? 另外,您是否确定要放在ImageView上的ImageView存在?

replace the RelativeLayout with 将RelativeLayout替换为

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

there can be only one xmlns attribute there are two in your code 只能有一个xmlns属性,您的代码中有两个

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM