Problem with the Simple Music Player App

I want to display all the audio of a device in a list view. The app throws an exception on opening. I don't use an emulator. I test it on physical device by building the apk file directly. All the catch statements are being executed. The RAM on my laptop is very less so I'll be unable to run this on the emulator and hence I'm unable to use of the logcat. I am stuck on this problem since a long time

import android.content.ContentResolver; import android.database.Cursor; import android.provider.MediaStore;  import; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import java.util.ArrayList;  public class MainActivity extends AppCompatActivity {  private ListView songsList; private ArrayList<String> songRows = new ArrayList<String>(); private ArrayAdapter<String> arrayAdpt; private int name, length; private Cursor cur; @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_main);      songsList = (ListView)findViewById(;      String[] requestColumns = {MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DURATION};     try {          cur = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, requestColumns, null, null, null);     }     catch(Exception ex){          Toast.makeText(this, "Unknown Exception", Toast.LENGTH_LONG).show();      }     try{         name = cur.getColumnIndex(MediaStore.Audio.Media.TITLE);         length = cur.getColumnIndex(MediaStore.Audio.Media.DURATION);     }     catch(Exception ex){         Toast.makeText(this, "Null Pointer Exception",     Toast.LENGTH_LONG).show();     }     try{         cur.moveToFirst();         while(!cur.isAfterLast()) {             songRows.add("Title "+cur.getString(name)+" Duration "+cur.getInt(length));             cur.moveToNext();         }     }     catch(Exception ex){         Toast.makeText(this, "Exception", Toast.LENGTH_LONG).show();     }      arrayAdpt = new ArrayAdapter<String>(this,         android.R.layout.simple_list_item_1, songRows);     songsList.setAdapter(arrayAdpt); } } 


Category: music player Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C), All Rights Reserved.

processed in 0.209 (s). 12 q(s)