Android 安卓:更改视图顺序会导致“;不幸的是,应用程序已停止;好啊为什么?

Android 安卓:更改视图顺序会导致“;不幸的是,应用程序已停止;好啊为什么?,android,layout,view,emulation,Android,Layout,View,Emulation,我有一个名为“Yamba”的应用程序。它拥有的唯一布局XML文件是: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"

我有一个名为“Yamba”的应用程序。它拥有的唯一布局XML文件是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/titleStatus"
        android:textSize="30sp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top|center_horizontal"
        android:hint="@string/hintText" />

    <TextView
        android:id="@+id/textCounter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:text="000" />

    <Button
        android:id="@+id/buttonId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/buttonUpdate"
        android:textSize="20sp" />

</LinearLayout>
更改后,模拟器显示:
不幸的是,Yamba已停止“OK


当我将它恢复到以前的顺序时,一切都很好。为什么?

当我对不合理的事情有疑问时。项目清理/退出eclipse并重新打开


我以前遇到过类似这样的奇怪事情,这就是最终解决问题的原因。

当您更改XML布局中视图的顺序时,它们的数字ID会更改(从上到下分配),然后当您在代码中引用前面的ID时,例如在
findviewbyd()中
您将得到错误的一个和一个
ClassCastException
(我猜是因为您没有包含logcat)


建筑前的清洁将解决问题。

这实际上很有道理。比我的日食理论更重要。+1。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/titleStatus"
        android:textSize="30sp" />

    <TextView
        android:id="@+id/textCounter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:layout_marginRight="10dp"
        android:text="000" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:gravity="top|center_horizontal"
        android:hint="@string/hintText" />

    <Button
        android:id="@+id/buttonId"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/buttonUpdate"
        android:textSize="20sp" />

</LinearLayout>