最近在学习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的更多相关文章

  1. 关于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 ...

  2. 加载程序到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 ...

  3. 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 ...

  4. 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 ...

  5. java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析

    报这个错,只有一个原因,就是你转化的类型不对. 如果你的类是一个单实体类,也就是没有继承或是接口别的类. public class HjmServiceImpl {} 那么这样写就可以: HjmSer ...

  6. 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 ...

  7. java.lang.ClassCastException android.widget.RelativeLayout LayoutParams 异常

    1.在xml布局文件如下所示: <RelativeLayout android:layout_width="match_parent" android:layout_heig ...

  8. Exception: java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams

    RelativeLayout title_bg = (RelativeLayout)FTU_Bluetooth.this.findViewById(R.id.titlebar); LinearLayo ...

  9. 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 ...

随机推荐

  1. js中的this指针(二)

    在 js 中声明并定义一个函数后,除了定义时传入的形式参数,函数还会接收到 2 个附加的参数:this 和 arguments. this 指针的值取决于调用时的模式. 当这个函数被保存为对象的一个属 ...

  2. PyCharm/IntelliJ IDEA Golang开发环境搭建(最方便快捷的GO语言开发环境)

    IntelliJ太牛了.为了配置Go语言开发环境,折腾了半天,下IDE(Sublime Text,IntelliJ Idea),然后装Go插件.装Go插件还要下载插件项目源码,编译等等,Sublime ...

  3. VS2012打开解决方案崩溃或点击项目崩溃

    打开项目文件就VS2012就崩溃 解决方案: 步骤1:开始-->所有程序-->Microsoft Visual Studio 2012-->Visual Studio Tools-- ...

  4. overload, override和overwrite之间的区别

    Overload.Overwrite和Override的概念比较容易混淆,而且Overwrite和Override的中文翻译五花八门,让人很Confuse,顾保持英文原意: Overload  重载 ...

  5. OGNL语言

                                                             OGNL 一.概述 以下内容摘自Ognl的官网: OGNL stands for Ob ...

  6. JavaScript插件架构

    1.HTML布局规则 默认情况下,所有的插件都可以通过设置特定的HTML代码和相应的属性来实现.也就是说,在网页加载的时候,JavaScript代码会自动检测这些标记,并自动绑定相应的事件,而无需添加 ...

  7. maven3 手动安装本地jar到仓库

    安装命令: mvn install:install-file -Dfile={Path/to/your/ojdbc.jar} -DgroupId=com.oracle -DartifactId=ojd ...

  8. Appium for Mac 环境准备篇

    之前写过一篇Appium for windows的文章,因为是09年的T400,启动Android模拟器的时候死机三次,那就公司申请台Macbook air吧,15寸的Macbook Pro实在太重了 ...

  9. 解决activity加上Theme.Translucent.NoTitleBar 页面跳转显示桌面

    自定义style 继承Theme.Translucent.NoTitleBar       <style name="My.Translucent" parent=" ...

  10. CentOS6.5下安装apache2.2和PHP 5.5.28

    CentOS6.5下安装apache2.2 1. 准备程序 :httpd-2.2.27.tar.gz 下载地址:http://httpd.apache.org/download.cgi#apache2 ...