2014-11-20 39 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

相關問題