0

I am making a mp3 app for a class project. It's supposed to read the path of every mp3 file in an sd card and put them in a list, but it crashes every time I attempt to access it.I tried to display a element using textview after five seconds, and it crashed again, so I know the problem is in the list.

Help? Thank you! P.S - Yes, there are mp3 files in the directory.

class mpfilter implements FilenameFilter {
public boolean accept(File dir, String name) {
    return(name.endsWith(".mp3"));
}


void update() {{



    File home= new File(path);
    if(home.listFiles(new mpfilter()).length>0) {
         for( File file: home.listFiles( new mpfilter())) {
             songs.add(file.getName());
         }
    }}
}

     Mp= new MediaPlayer();
     path= new String("/Card/music/");
     songs= new ArrayList<String>();


    Play.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Mp.reset();
            Mp.setDataSource(path+songs.get(x));
            Mp.prepare();


            Mp.start();
        }
Metafity
  • 35
  • 1
  • 6
  • Can you check the [logcat](http://developer.android.com/tools/help/logcat.html) output for your application? Is there something (e.g. a stacktrace) shown? – Stefan Freitag Jan 09 '16 at 20:11
  • Also, it looks like you posted a lot of extra code that makes it difficult to isolate the portion of code you think is causing trouble. Can you update your post with a [Simple Self-Contained Example](http://sscce.org/) that contains only the code you think is failing? This isn't a useless exercise -- it will help us help you, and often you will find the real cause of an error in the process of trying to isolate its cause. – sigpwned Jan 09 '16 at 20:22
  • @sigpwned logcat shows a index 0 error, I don't really know how to use it, Sorry. Edited the code though. I have a function update which using the filefilter should add the name of every mp3 file in the specified path, to the arraylist songs. – Metafity Jan 09 '16 at 21:17
  • The "index 0 error" sounds like a good starting place. Can you paste the stack trace in your question? Stack trace examples are pasted on [this question](http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors) so you know what to look for! – sigpwned Jan 10 '16 at 15:53

0 Answers0