当前位置: 代码迷 >> Android >> 类型异常
  详细解决方案

类型异常

热度:867   发布时间:2016-05-01 22:31:00.0
类型错误
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));
  相关解决方案