我在Android中遇到以下异常,点击按钮将我从一个活动带到另一个活动(我是Android开发的新手,所以它可能不是最明亮的问题):
java.lang.ClassCastException:android.widget.RelativeLayout无法强制转换为android.widget.EditText
我已经尝试过多次清理项目了,我已经尝试过Android Tools中的Fix Project Properties选项,我已经检查了我的xml是否有错误,但我似乎无法弄清楚这一点.我必须提一下,该按钮运行良好一段时间,直到发生此异常.
这是我的xml:
这是抛出异常的活动中的onCreate方法:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_customer_info); this.editMail = (EditText)findViewById(R.id.editCustomerEmail); this.editName = (EditText)findViewById(R.id.editCustomerName); this.editPhone = (EditText)findViewById(R.id.editCustomerPhone); // the exception points me here }
njzk2.. 5
你的代码说:
editCustomerPhone
是一个相对布局.
你的代码说:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/editCustomerPhone"
editCustomerPhone
是一个相对布局.