Getting a null pointer exeception when using scanner to read file
<p>I want to read a text file and parse the string until eof..here is a code snippet.. programs.txt is under assets directory</p>

<pre><code>    public void insert_programs() throws FileNotFoundException {
    BufferedReader bfr = null;
    try {
        bfr = new BufferedReader(new 
                InputStreamReader(getAssets().open("programs.txt"))); // &lt;-- NPE occurs on that line 

    } catch (IOException e) {
        e.printStackTrace();
    }
    Scanner pgm = new Scanner(bfr);
    pgm.useDelimiter("*{3}");
    while (pgm.hasNext()) {
        String str = pgm.next();
            process(str);
        }
    }
</code></pre>

<p>Logs </p>

<pre><code>03-14 18:05:34.936: E/AndroidRuntime(467):  at dalvik.system.NativeStart.main(Native Method)
03-14 18:05:34.936: E/AndroidRuntime(467): Caused by: java.lang.NullPointerException
03-14 18:05:34.936: E/AndroidRuntime(467):  at android.content.ContextWrapper.getAssets(ContextWrapper.java:74)
03-14 18:05:34.936: E/AndroidRuntime(467):  at c.theworld.com.nikhil.Database.insert_programs(Database.java:40)
</code></pre>
