关于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中
MainActivity中
很明显的错误.....
组件类型都不一样 把类型弄一致就ok了
在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了
相关文章推荐
- 错误android.widget.ImageButton cannot be cast to android.widget.Button
- 【Android】程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- 解决android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
- 解决方法 android.view.AbsSavedState$1 cannot be cast to android.widget.CompoundButton$SavedState
- 关于Android.widget.Button cannot be cast to com.esri.android.map.MapView错误的问题
- APP程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- 安卓出现错误: java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
- 【Android】程序崩溃错误为Android.widget,textView cannot be cast to android.widget.button
- android.widget.Button cannot be cast to android.widget.Gallery
- Android 解决bug:异常提示"ListView cannot be cast to android.widget.BaseAdapter "
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
- 解决android.widget.LinearLayout cannot be cast to android.widget.ListView问题
- 异常 java.lang.ClassCastException:cannot be cast to android.widget.HeaderViewListAdapter.的解决方法
- java.lang.ClassCastException: android.widget.TextView cannot be cast to android.widget.EditText
- java.lang.ClassCastException: android.widget.ImageView cannot be cast to android.widget.TextView解决办法
- java.lang.ClassCastException~android.widget.ImageView cannot be cast to android.widget.Button~
- android的ui组件布局提示:android.widget.XXX cannot be cast to android.widget.YYY解决
- ClassCastException: android.widget.Button cannot be cast to android.view.Vi
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
- 解决 android.view.ViewGroup$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams