专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Android

类型异常

发布时间:2010-05-30 10:54:00 文章来源:www.iduyao.cn 采编人员:星星草
类型错误
1、首先定义public class DragListView extends ListView类。
2、在其他Activity中定义private DragListView m_lstvSong;
3、获取对象m_lstvSong = (DragListView)((ListView) findViewById(R.id.lstvSong));

xml文件如下
<ListView
  android:id="@+id/lstvSong"
  android:layout_width="wrap_content"
  android:layout_height="389dp"
  android:layout_x="0dp"
  android:layout_y="72dp" >
</ListView>

问题:第3句会出错,为什么?怎么解决?

------解决方案--------------------
那你改为“fill_parent”试试呗
------解决方案--------------------
<ListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" >
</ListView>
改为
<包名.DragListView 
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" />

布局文件里放的是ListView。你如何向下转型? 向下转型的前提是作为开发者你要确定你要向下转的那个对象就是那个子类。

------解决方案--------------------
<包名.ListView
android:id="@+id/lstvSong"
android:layout_width="wrap_content"
android:layout_height="389dp"
android:layout_x="0dp"
android:layout_y="72dp" >
</ListView>

ListView m_lstvSong = ((ListView) findViewById(R.id.lstvSong));
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: