java.lang.ClassCastException: cannot be cast to android.widget.RadioButton错误

                                                                                     图一

错误提示如图一,错误代码如图二,mMandatoryMeasuresRg的布局代码如图三。

原因:类型强转错误,RadioGroup内部包含的三个控件的顺序分别为TextView(0),RadioButton(1),RadioButton(2)

而在设置RadioButton的默认选中时错误的强转了第0个控件TexView,导致程序崩溃。。。。。

java.lang.ClassCastException: cannot be cast to android.widget.RadioButton错误

                                                                                            图二

java.lang.ClassCastException: cannot be cast to android.widget.RadioButton错误

                                                                           图三

相关文章: