ListActivity crash
<p>I wish to open a list of files in a directory when i clicked on a button. Then tap on a item on the list to open the file in a texteditor. But i the app crashes when i run it. any where i have error on the codes?</p>

<pre><code>public class LogActivity extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    //click to view log file
    Button openButton = (Button)this.findViewById(R.id.btn_opentext);
    openButton.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
          File file = new File (Environment.getExternalStorageDirectory(), "/TEST");

          File[] listfiles = null;

          if(file.isDirectory())
              listfiles = file.listFiles();

          for(int i=0;i&lt;listfiles.length;i++)
              Log.i("FileName", listfiles[i].getName());

        if (!file.exists())
        {
            Toast.makeText(LogActivity.this, "File does not exist", Toast.LENGTH_SHORT).show();
        }
        else
        {

          setListAdapter(new ArrayAdapter&lt;File&gt;(LogActivity.this,
                    android.R.layout.simple_list_item_1, listfiles));
            //tap on item on list to open file
            Intent intent = new Intent();
            intent.setAction(android.content.Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(file), "text/plain");
            startActivity(intent);
        }  

      }
    });
</code></pre>
