app close unexpectaly

Put your problem here if it does not fit any of the other categories.

app close unexpectaly

Postby ditsikts » Mon Sep 19, 2011 2:06 pm

the result of this app is to read SD for .avi files and show them in listview
Any tip is welcome.

sory for poor english:(
projecthttp://www.megaupload.com/?d=STTQIWAU

activity
Code: Select all
package mhtsos.videoplayer;

import android.app.Activity;
import android.os.Bundle;
import java.io.File;
import java.io.FilenameFilter;
import java.util.ArrayList;
import java.util.List;
import android.view.View;
import android.widget.ArrayAdapter;
import mhtsos.videoplayer.AviFilter;
import android.widget.Toast;
import android.app.ListActivity;
import android.widget.ListView;
import android.widget.Toast;
class AviFilter implements FilenameFilter {
    public boolean accept(File dir, String name) {
        return (name.endsWith(".avi"));
    }
}


public class SuperPlayerActivity extends ListActivity {
   private static final String MEDIA_PATH = new String("/sdcard/");
   private ArrayList<String> movies = null;
   Toast t = new Toast(SuperPlayerActivity.this);
    //t.makeText(SuperPlayerActivity.this, "Volume set to Max"
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        this.setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, movies));
       
        updateMovieList();
       
       
    }
    public void updateMovieList() {
       File home = new File(MEDIA_PATH);
      if (home.listFiles( new AviFilter()).length > 0) {
          for (File file : home.listFiles( new AviFilter())) {
             movies.add(file.getName());
          }
      if (movies==null){
         t.makeText(SuperPlayerActivity.this, "No movie found!",Toast.LENGTH_SHORT).show();
      }//if
      else{
          ArrayAdapter<String> movieList = new ArrayAdapter<String>(this,R.layout.movie_item,movies);
          setListAdapter(movieList);
      }//else
      }       
    }
}
ditsikts
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 19, 2011 1:38 pm

Top

Re: app close unexpectaly

Postby Dockland » Mon Sep 19, 2011 2:39 pm

Examine LogCat output.
I suspect
Code: Select all
    this.setListAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, movies));  // variable 'movies' are null, don't set list adapter or set new empty adapter.


PS Have not looked at the project.
PS PS Sorry for not fluent and horrible English :)
Dockland
Developer
Developer
 
Posts: 37
Joined: Wed Jul 27, 2011 12:29 pm

Re: app close unexpectaly

Postby ditsikts » Mon Sep 19, 2011 3:55 pm

finally i made it run :)
ditsikts
Freshman
Freshman
 
Posts: 4
Joined: Mon Sep 19, 2011 1:38 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 23 guests