您的位置:首页 > 移动开发 > Android开发

关于java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.Edit 错误的解决

2014-10-15 18:35 567 查看
把程序配置到手机上,程序直接就挂掉了

在logcat 可以看见错误:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myyt.savefiletosdcard/com.myy.savefiletosdcard.MainActivity}: java.lang.ClassCastException: android.widget.Button cannot be cast to android.widget.EditText

错误的代码

xml中

</pre><p><pre name="code" class="html">    <Button
android:id="@+id/bt_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="saveMsg"
android:text="保存" />


MainActivity中

<pre name="code" class="java">    protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et_msg = (EditText) findViewById(R.id.bt_msg);
}




很明显的错误.....

组件类型都不一样 把类型弄一致就ok了
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐