2014-11-20 26 views
0

我没有看到任何错误,调试不是很有用。我怎样才能解决这个错误?android.widget.FrameLayout不能转换为android.widget.ListView

这是代码的一部分,出现错误的最后一行内

提前感谢!

@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

是我的回答有帮助吗?如果有帮助,请考虑积极和/或接受。 – 2014-11-24 17:41:20

+0

这真的很有帮助!非常感谢! – KillDash9 2014-11-24 18:15:11

+0

真棒,欢呼! – 2014-11-24 18:21:44

回答

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" > 
+0

我得到了同样的问题,感谢鲍威尔的回答,对于上述问题,我想简单地修改 – byron 2016-06-06 19:43:11

相关问题