how to get a list of files in the cache directory?
<p>I'm trying to get a list of files in the cache directory but I can't seem to see what I'm doing wrong,can anyone help please?</p>

<pre><code>public class CacheActivity extends Activity {

    private ListView lv;
    private File[] fileName;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cache);

        lv = (ListView) findViewById(R.id.cacheList);

        ArrayAdapter&lt;File&gt; adapter = new ArrayAdapter&lt;File&gt;(this,
                android.R.layout.simple_list_item_1, android.R.id.text1,
                fileName);
        lv.setAdapter(adapter);

    }

    public void listCache(Context context) {
        fileName = context.getCacheDir().listFiles();

    }
}
</code></pre>

<p>the program force quits unexpectedly.</p>

<p>I've changed the code to the following the program doesn't crash anymore but it doesn't show any files(cache files) either.</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cache);

        lv = (ListView) findViewById(R.id.cacheList);
        // context = getApplicationContext();
        fileName = getCacheDir().listFiles();

        ArrayAdapter&lt;File&gt; adapter = new ArrayAdapter&lt;File&gt;(this,
                android.R.layout.simple_list_item_1, android.R.id.text1,
                fileName);
        lv.setAdapter(adapter);

    }




&lt;ListView
        android:id="@+id/cacheList"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="100dp" &gt;
    &lt;/ListView&gt;
</code></pre>
