我正在尝试使用mediastore获取Artist表中的no。我能够获得所有艺术家的名字,但是当我试图获得NUMBER_OF_TRACKS
我收到错误时。我搜索并找到this但这不是我的问题。这是我的代码< / p>
try {
String[] proj = {MediaStore.Audio.Artists._ID,
MediaStore.Audio.Artists.ARTIST,
MediaStore.Audio.ArtistsColumns.NUMBER_OF_TRACKS,
MediaStore.Audio.Artists.ARTIST_KEY
,MediaStore.Audio.Artists.NUMBER_OF_ALBUMS
};// Can include more data for more details and check it.
String selection = null;
String[] selectionArgs = null;
String sortOrder = MediaStore.Audio.Artists.ARTIST + " ASC";
Cursor audioCursor = getContentResolver().query(MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, proj, selection, selectionArgs, sortOrder);
if (audioCursor != null) {
if (audioCursor.moveToFirst()) {
do {
int artistname = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
int artist_id = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists._ID);
int artist_track = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.NUMBER_OF_TRACKS);
int artist_key = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST_KEY);
Mediafileinfo info = new Mediafileinfo();
info.setArtistname(audioCursor.getString(artistname));
info.setArtistkey(audioCursor.getString(artist_key));
info.setArtist_track(audioCursor.getInt(artist_track));
info.setArtist_id(audioCursor.getString(artist_id));
audioList.add(info);
} while (audioCursor.moveToNext());
,适配器代码为
Mediafileinfo item = (Mediafileinfo) getItem(position);
TextView artist = (TextView) view.findViewById(R.id.textView);
TextView count = (TextView) view.findViewById(R.id.textView2);
artist.setText(item.artistname);
count.setText(item.artist_track);
我做错了什么?以及如何在mediastore中使用No of Track任何一个例子 当我尝试我得到这样的错误
FATAL EXCEPTION: main
android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.Resources.getText(Resources.java:233)
at android.support.v7.widget.ResourcesWrapper.getText(ResourcesWrapper.java:52)
at android.widget.TextView.setText(TextView.java:3657)
at com.example.neelay.level10.CustomAdapter.getView(CustomAdapter.java:35)
at android.widget.AbsListView.obtainView(AbsListView.java:2267)
at android.widget.ListView.makeAndAddView(ListView.java:1769)
at android.widget.ListView.fillDown(ListView.java:672)
at android.widget.ListView.fillFromTop(ListView.java:733)
at android.widget.ListView.layoutChildren(ListView.java:1622)
at android.widget.AbsListView.onLayout(AbsListView.java:2102)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.RelativeLayout.onLayout(RelativeLayout.java:953)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.support.design.widget.CoordinatorLayout.layoutChild(CoordinatorLayout.java:1139)
at android.support.design.widget.CoordinatorLayout.onLayoutChild(CoordinatorLayout.java:833)
at android.support.design.widget.ViewOffsetBehavior.layoutChild(ViewOffsetBehavior.java:63)
at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:135)
at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)
at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1364)
at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:846)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.FrameLayout.onLayout(FrameLayout.java:463)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1730)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1588)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1487)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.FrameLayout.onLayout(FrameLayout.java:463)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1730)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1588)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1487)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.widget.FrameLayout.onLayout(FrameLayout.java:463)
at android.view.View.layout(View.java:13902)
at android.view.ViewGroup.layout(ViewGroup.java:4476)
at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1876)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1697)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4222)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4793)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:808)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我在电脑上使用Razorsql查看了数据库本身。数据保存在名为artist_info的视图中。那里需要的细节。 而不是
MediaStore.Audio.Artists.NUMBER_OF_TRACKS);
试
MediaStore.Audio.ArtistColumns.NUMBER_OF_TRACKS;
找到这个例子:
MediaStore.Audio.Artists.EXTERNAL_CONTENT_URI, new String[] {
BaseColumns._ID,
ArtistColumns.ARTIST,
ArtistColumns.NUMBER_OF_ALBUMS,
ArtistColumns.NUMBER_OF_TRACKS }, null, null,null);