Android programming crash null pointer exception
<p>hey everyone at the moment im trying to display all the files in a certain folder on the android devices sd card in a <code>ListView</code> and so far im having bad luck,It crashes with a nullpointer exception so i was wondering if anyone here could shine some lite on my proble ill post my activity and logcat below and thanks.</p>

<p>Activity</p>

<pre><code>package com.mkyong.android;

import java.io.File;

import java.util.ArrayList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import android.view.View;

public class ListMobileActivity extends ListActivity {


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.res);

    }
        public ArrayList&lt;String&gt; GetFiles(String DirectoryPath) {
            ArrayList&lt;String&gt; MyFiles = new ArrayList&lt;String&gt;();
            File f = new File(DirectoryPath);

            f.mkdirs();
            File[] files = f.listFiles();
            if (files.length == 0)
                return null;
            else {
                for (int i=0; i&lt;files.length; i++) 
                    MyFiles.add(files[i].getName());
            }

            return MyFiles;
        }
        {
        ListView lv;
        ArrayList&lt;String&gt; FilesInFolder = GetFiles("/sdcard/RootBox");
        lv = (ListView)findViewById(R.id.listView1);

        lv.setAdapter(new ArrayAdapter&lt;String&gt;(this,
            android.R.layout.simple_list_item_1, FilesInFolder));

        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {

             }
        });
    }




    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {

        //get selected items
        String selectedValue = (String) getListAdapter().getItem(position);
        Toast.makeText(this, selectedValue, Toast.LENGTH_SHORT).show();

    }

}
</code></pre>

<p>and logcat</p>

<pre><code>05-24 06:42:28.992: E/AndroidRuntime(796): FATAL EXCEPTION: main
05-24 06:42:28.992: E/AndroidRuntime(796): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/com.mkyong.android.ListMobileActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
05-24 06:42:28.992: E/AndroidRuntime(796):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-24 06:42:28.992: E/AndroidRuntime(796):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-24 06:42:28.992: E/AndroidRuntime(796):  at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-24 06:42:28.992: E/AndroidRuntime(796):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-24 06:42:28.992: E/AndroidRuntime(796):  at android.os.Handler.dispatchMessage(Handler.java:99)
</code></pre>
