java.lang.ClassCastException:android.widget.LinearLayout无法强制转换为android.widget.EditText
在发布这个问题之前,我已经查看了和,但我无法从这两个问题中找到任何帮助 我得到了这个例外-java.lang.ClassCastException:android.widget.LinearLayout无法强制转换为android.widget.EditText,java,android,android-layout,exception,Java,Android,Android Layout,Exception,在发布这个问题之前,我已经查看了和,但我无法从这两个问题中找到任何帮助 我得到了这个例外- 09-14 11:57:57.813: E/AndroidRuntime(8135): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.firstpage/com.example.firstpage.CreateGroup}: java.lang.ClassCastException: andro
09-14 11:57:57.813: E/AndroidRuntime(8135): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.firstpage/com.example.firstpage.CreateGroup}: java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.EditText
09-14 11:57:57.813: E/AndroidRuntime(8135): at com.example.firstpage.CreateGroup.onCreate(CreateGroup.java:43)
单击“09-14 11:57:57.813:E/AndroidRuntime(8135):在com.example.firstpage.CreateGroup.onCreate(CreateGroup.java:43)”时显示的代码部分是-
特定部分的XML文件是-
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/DimGray"
android:gravity="top|center"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<EditText
android:id="@+id/editTextcg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:ems="10"
android:hint="Group Name" >
<requestFocus />
</EditText>
我为什么会遇到这个异常,如何纠正
更新:
正如Falmari和Ted Hopp所说,我清理了我的项目,现在它工作正常。感谢您的帮助。清理您的项目。另外,如果这是您的整个xml文件,那么您将丢失线性布局的结束。@Falmari这不是整个xml文件。请务必清理您的项目。另外,如果您有限定的资源目录(layout-[something]),请确保正在加载的布局是您认为的布局。运行Android lint检查其他可能的错误(例如,同一个id在同一个文件中被使用了两次)也不会有什么坏处。有时关闭ecllipse并重新打开可以解决此错误。在某个时间更改xml文件时,R.java停止生成导致异常的文件
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/DimGray"
android:gravity="top|center"
android:orientation="horizontal"
android:paddingBottom="5dp"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:paddingTop="5dp" >
<EditText
android:id="@+id/editTextcg1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
android:ems="10"
android:hint="Group Name" >
<requestFocus />
</EditText>