标签:
最近在学习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
标签:
原文地址:http://www.cnblogs.com/expiator/p/5842390.html