Android - Recursive file search gives NullPointerException
<p>I have the following function to recursively search for a string within files, however it keeps giving a <code>NullPointerException</code>. When it is first called it seems to work, but once it recursively calls itself, <code>files</code> is <em>null</em>.</p>

<pre><code>public void recursiveSearch(File searchDirectory, String searchString){
    File[] files = searchDirectory.listFiles(); 
        for (int i = 0; i &lt; files.length; i++) {
            if (files[i].isDirectory()){
                recursiveSearch(files[i], searchString);
            }
            if (files[i].getName().contains(searchString)){
                searchResultFiles.add(files[i]);
            }
        }
}
</code></pre>

<p>Here is an example of how it is called:</p>

<pre><code>recursiveSearch("/", "abc");
</code></pre>
