java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
最近在学习drawerLayout时,遇到这个bug。如下示:
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView
原因:
可能是没有在适配器参数内加入TextView的id.
解决方案:
将原来的适配器参数代码
mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,datas));
修改为以下形式即可:
mDrawerList.setAdapter(new ArrayAdapter<String>(this,R.layout.list_item,R.id.text_view,datas));
其他的解决方案,参见stack overflow:
http://stackoverflow.com/questions/20290735/java-lang-classcastexception-android-widget-linearlayout-cannot-be-cast-to-andr
http://stackoverflow.com/questions/10869197/android-widget-linearlayout-cannot-be-cast-to-android-widget-textview
java.lang.ClassCastException: android.widget.RelativeLayout cannot be cast to android.widget.TextView的更多相关文章
- 关于android使用ksoap2报Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject
Caused by: java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serializa ...
- 加载程序到android虚拟机报错: android.widget.RelativeLayout cannot be cast to android.widget.Button
05-23 02:53:48.416: E/Trace(875): error opening trace file: No such file or directory (2) 05-23 02:5 ...
- java.lang.ClassCastException: oracle.sql.CLOB cannot be cast to oracle.sql.CLOB
错误现象: [framework] 2016-05-26 11:34:53,590 -INFO [http-bio-8080-exec-7] -1231863 -com.dhcc.base.db.D ...
- java.lang.ClassCastException: oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp
http://stackoverflow.com/questions/13269564/java-lang-classcastexception-oracle-sql-timestamp-cannot ...
- java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析
报这个错,只有一个原因,就是你转化的类型不对. 如果你的类是一个单实体类,也就是没有继承或是接口别的类. public class HjmServiceImpl {} 那么这样写就可以: HjmSer ...
- java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.w ...
- java.lang.ClassCastException android.widget.RelativeLayout LayoutParams 异常
1.在xml布局文件如下所示: <RelativeLayout android:layout_width="match_parent" android:layout_heig ...
- Exception: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams
RelativeLayout title_bg = (RelativeLayout)FTU_Bluetooth.this.findViewById(R.id.titlebar); LinearLayo ...
- java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.ProgressBar$SavedState
java.lang.ClassCastException: android.view.AbsSavedState$1 cannot be cast to android.widget.Progress ...
随机推荐
- linux服务之maven
curl -O http://mirrors.noc.im/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.zip [root@d ...
- selenium多个窗口切换
浏览器里面支持多窗口打开,例如这样: html里面写了: target="_blank" 造成新打开一个窗口,但是selenium不会自动跳转到新的串口,需要自己切换: # 你打开 ...
- 【ASP.net】Equals 和 == 的区别
在比较Equals 和 ==的区别前.我们先来了解下相关的知识 C#数据类型 1.值类型 值类型有: 值类型包括:简单类型.结构类型.枚举类型:引用类型包括:Object 类型.类类型.接口.代表元. ...
- iOS中如何让TextView和TextField控件支持return键收起输入法
TextView和TextField控件是iOS中负责接收用户输入的控件,那当用户输入完成时怎么收起面板呢? 1.TextView和TextField控件获得焦点之后的第一反应就是弹出输入法面板: 2 ...
- 如何成为一名合格甚至优秀的个人草根站长(转载自ChinaZ)
这章本来不想写来的,后来琢磨琢磨还是废话一下吧.主要是想说下现在草根站长的状态和如何成为一名合格的甚至优秀的草站站长. 伟大的草根站长们,在某些媒体的超级忽悠下全来到网络上淘金来了,有在校的大学生,有 ...
- HTC Vive开发笔记之UI Guideline
本文转自HTC官方论坛,原址https://www.htcvive.com/cn/forum/chat.php?mod=viewthread&tid=1641&extra=page=1 ...
- 随便2--struct pointer
同为struct,如果struct中没有指针, C 和C++可以用等号赋值,但是一旦里面涉及到指针,就不能用等号,要用memcpy struct A{char v1[20];int v2;} a,b; ...
- oracle的char和varchar类型
源地址:https://zhidao.baidu.com/question/140310197.html varchar与char的区别就在于是否可变长度.char(5)就是定义一个5个字符长度的字符 ...
- .net 中生成二维码的组件
http://qrcodenet.codeplex.com/
- windows 装 Crypto.Cipher
python 2.7 先去官网下载,https://www.dlitz.net/software/pycrypto/ 回来装这个,http://download.csdn.net/download/d ...