定义了一个PersonListView类如下:
public class PersonListView extends ListView
{
public PersonListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
}res/layout/main.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
class="com.study.android.activity.MainActivity$PersonListView"
android:id="@+id/lv_person"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>MainActivity的onCreate方法:
setContentView(R.layout.main);
lv_item = (PersonListView) findViewById(R.id.lv_person);错误为:lv_item = (PersonListView) findViewById(R.id.lv_person)出现了ClassCastException请问前面的写法哪里出了问题吗
public class PersonListView extends ListView
{
public PersonListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
}res/layout/main.xml如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<View
class="com.study.android.activity.MainActivity$PersonListView"
android:id="@+id/lv_person"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>MainActivity的onCreate方法:
setContentView(R.layout.main);
lv_item = (PersonListView) findViewById(R.id.lv_person);错误为:lv_item = (PersonListView) findViewById(R.id.lv_person)出现了ClassCastException请问前面的写法哪里出了问题吗
解决方案 »
- 在android将信息写入指定的xml,怎么指定路径?
- 4.0以上版本如何获取添加APN权限
- 如何隐藏键盘?
- android Handler
- Android 更换皮肤
- android mediaplayer播放视频如何获取视频总长度?
- Android 应用里面怎么开发线性图标跟柱状图表和饼图呢?
- 关于百度地图API当中com.baidu.location.f这个Service的一个疑问
- 怎么进入子线程调试
- 请问:在service里面能否改变statusBar的颜色?
- 谁有c2dm的相关资料,最好有实例
- AlertDialog.Builder listview SimpleCursorAdapter删除项问题
<包名.PersonListView
android:id="@+id/lv_person"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
并不是类型转换的问题
内部类必须要用外部类的对象来new 才能创建对象