android上音频文件的列表视图

android上音频文件的列表视图,android,listview,audio,Android,Listview,Audio,我正在尝试收集设备外部源上的所有音频文件。当我在设备上运行时,会收到一条消息,上面写着“不幸地”“已停止”。我还没有找到问题仍然存在的地方。我在网上查了一下,发现很多例子都是这样做的,但没有任何效果 package com.example.djraspi; import java.util.ArrayList; import java.util.List; import android.os.Bundle; import android.provider.MediaStore; impo

我正在尝试收集设备外部源上的所有音频文件。当我在设备上运行时,会收到一条消息,上面写着“不幸地”“已停止”。我还没有找到问题仍然存在的地方。我在网上查了一下,发现很多例子都是这样做的,但没有任何效果

  package com.example.djraspi;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.provider.MediaStore;
import android.app.ListActivity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.database.Cursor;

public class MainActivity extends ListActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initMusicList();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private void initMusicList(){
String selection = MediaStore.Audio.Media.IS_MUSIC + " !=0";
String[] projection = {
MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.ARTIST_ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.DISPLAY_NAME,
MediaStore.Audio.Media.DURATION
};

Cursor cursor = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, null, null);
List<String> songList = new ArrayList<String>();
while(cursor.moveToNext()){
songList.add(cursor.getString(0) + 
"||" + cursor.getString(1) + "||" +   cursor.getString(2) + "||" +   cursor.getString(3) + "||" +  cursor.getString(4) + "||" +  cursor.getString(5) + "||" +  cursor.getString(6));
}
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_main, android.R.id.list, songList));


}

}
试试这个:

<ListView 
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" />

您正在使用
ListActivity
。在
XML
中将listView id设置为
android:id=“@android:id/list”

<ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp"
        android:listSelector="@drawable/menu_listitem_selector"/>

使用listview的id作为android的列表

<ListView 
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" />

你读过logcat吗?
它的意思是“java.lang.RuntimeException:您的内容必须有一个id属性为“android.R.id.list”的ListView,所以给出id列表,您就会找到解决方案。

请发布崩溃日志,以获取日志猫或错误日志?我是eclipse环境以及java和androidpost的新手,这里记录cat输出,您应该在发布您的问题之前搜索有关解决方案的信息,可能是重复的。。。。为什么你们不使用谷歌或不阅读例外…我做了,我尝试的所有其他解决方案都没有解决我的问题,我对这一点还是新手。如果每个人都有一个贴在上面的流浪汉,那么这个网站对学习有什么帮助呢。这是我的日志文件:
<ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginTop="20dp"
        android:listSelector="@drawable/menu_listitem_selector"/>
<ListView 
     android:id="@android:id/list"
     android:layout_width="fill_parent"
     android:layout_height="fill_parent" />