android:ListActivity unable to open sdcard mp3 neither play mp3 -


listactivity closes when trying open saved recordings sd card in recording activity , new activity, showing listview starts not open sdcard contents mp3 externalsdcard play file in it! thanks

here code

public class droid extends listactivity {      private static final string media_path = new string(environment             .getexternalstoragedirectory().getpath());     private list<string> songs = new arraylist<string>();     private mediaplayer mp = new mediaplayer();     private int currentposition = 0;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.songlist);         updatesonglist();     }      public void updatesonglist() {         file home = new file(media_path);         if (home.listfiles(new filter()).length > 0) {             (file file : home.listfiles(new filter())) {                 songs.add(file.getname());             }              arrayadapter<string> songlist = new arrayadapter<string>(this,                     r.layout.song_item, songs);             setlistadapter(songlist);         }     }      class filter implements filenamefilter {         public boolean accept(file dir, string name) {             return (name.endswith(".3gp"));         }     }      @override     protected void onlistitemclick(listview l, view v, int position, long id) {         currentposition = position;         playsong(media_path + songs.get(position));     }      private void playsong(string songpath) {         try {              mp.reset();             mp.setdatasource(songpath);             mp.prepare();             mp.start();              // setup listener next song starts automatically             mp.setoncompletionlistener(new oncompletionlistener() {                  public void oncompletion(mediaplayer arg0) {                     nextsong();                 }              });          } catch (ioexception e) {             log.v(getstring(r.string.app_name), e.getmessage());         }     }      private void nextsong() {         if (++currentposition >= songs.size()) {             // last song, reset currentposition             currentposition = 0;         } else {             // play next song             playsong(media_path + songs.get(currentposition));         }     } } 

songlist.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <listview android:id="@android:id/list"               android:layout_width="fill_parent"               android:layout_height="0dip"               android:layout_weight="1"               android:drawselectorontop="false"/>      <textview android:id="@id/android:empty"               android:layout_width="fill_parent"               android:layout_height="fill_parent"               android:text="@string/media"/> </linearlayout> 

song_item.xml

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:orientation="vertical" >      <textview android:id="@android:id/text1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"/> </linearlayout> 

force closes new class droid on option menu

    case r.id.droid:       intent dr = new intent(mainactivity.this, droid.class);       startactivity(dr);       return true;   

you did not declared drod activity @ manifest.

if other works, else should post stacktrace.


Comments