我没有看到任何错误,调试也不是很有用。我该如何解决这个错误?
这是代码的一部分,错误出现在最后一行
中提前致谢!
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_selfie_list);
mMatrixCursor = new MatrixCursor(new String[]{"_id","_data","_details"});
ListView lVThumbnail = (ListView) findViewById(R.id.selfie_list_layout);
mAdapter = new SimpleCursorAdapter(
getBaseContext(),
R.layout.activity_selfie_list,
null,
new String[] { "_data","_details"} ,
new int[] { R.id.img_thumbnail,R.id.tv_details},
0
);
lVThumbnail.setAdapter(mAdapter);
这是使用的布局,第一个是列表片段(因为我使用列表和详细的片段),第二个是列表布局。 :
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/selfie_list"
android:name="com.lordpato.dailyselfie.SelfieListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
tools:context="com.lordpato.dailyselfie.SelfieListActivity"
tools:layout="@layout/lv_layout" />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/selfie_list_layout"
android:layout_height="75dp" >
<ImageView
android:id="@+id/img_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:adjustViewBounds="true"
android:padding="5dp"
/>
<TextView
android:id="@+id/tv_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/img_thumbnail"
android:padding="5dp"
/>
</RelativeLayout>
答案 0 :(得分:1)
selfie_list_layout 不是ListView。
ListView lVThumbnail = (ListView) findViewById(R.id.selfie_list_layout);
...
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:id="@+id/selfie_list_layout"
android:layout_height="75dp" >