error:no such coloumn while getting media files

  • Thread starter Thread starter Android Central Question
  • Start date Start date
A

Android Central Question

in my music player i want to get songs from album,but it gives me error in the logs.please explain me this error why this occurs.i saw all the previous question on stackoverflow about this problem but couldnt understand,please help.

public void getAlbumsLists() {
final Uri uri = MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI;
_id = MediaStore.Audio.Albums._ID;
final String album_name = MediaStore.Audio.Albums.ALBUM;
final String artist = MediaStore.Audio.Albums.ARTIST;
tracks = android.provider.MediaStore.Audio.Albums.NUMBER_OF_SONGS;
final String data=MediaStore.Audio.Media.DATA;
final String id1=MediaStore.Audio.Media._ID;
final String tit=MediaStore.Audio.Media.TITLE;
final String nam=MediaStore.Audio.Media.DISPLAY_NAME;
final String typ=MediaStore.Audio.Media.MIME_TYPE;
final String[] columns = {_id, album_name, artist, tracks,data,id1,tit,nam,typ};

cursor = getContext().getContentResolver().query(uri, columns,null, null, null);
if (cursor != null && cursor.moveToFirst()&&cursor.getCount()>0)
do {
int x=cursor.getColumnCount();
System.out.println(x);
String id = (cursor.getString(cursor.getColumnIndex(_id)));
String name = cursor.getString(cursor.getColumnIndex(album_name));
String artist2 = cursor.getString(cursor.getColumnIndex(artist));
String nr = cursor.getString(cursor.getColumnIndex(tracks));
String data1=cursor.getString(cursor.getColumnIndexOrThrow(data));
String id2=cursor.getString(cursor.getColumnIndex(id1));
String title=cursor.getString(cursor.getColumnIndex(tit));
String name1=cursor.getString(cursor.getColumnIndex(nam));
String type=cursor.getString(cursor.getColumnIndex(typ));
albumInfo s = new albumInfo(id, name, artist2, nr,data,id2,title,name1,type);
albumList.add(s);
} while (cursor.moveToNext());

if (cursor != null) {
cursor.close();
}
recyclerView1.setAdapter(albumAdapter);
}

this is logcat

android.database.sqlite.SQLiteException: no such column: data (code 1): , while compiling: SELECT _id, album, artist, numsongs, duration, _id, title, _display_name, mime_type FROM album_info at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:179) at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135) at android.content.ContentProviderProxy.query(ContentProviderNative.java:418) at android.content.ContentResolver.query(ContentResolver.java:754) at android.content.ContentResolver.query(ContentResolver.java:704) at android.content.ContentResolver.query(ContentResolver.java:662) at layout.BlankFragment.getAlbumsLists(BlankFragment.java:154) at layout.BlankFragment.onCreateView(BlankFragment.java:138)