FATAL EXCEPTION : main and Nullpointer
<p>I've had this really annoying problem for a couple of days, and I cannot quite seem to solve it. I am trying to open a <code>.csv</code> file, so I imported it into the <code>res/raw/</code> folder of my project. Then I am trying to open and read it via the <code>getResources()</code> method, and that's exactly where I get the <code>NullPointerException</code>. Here's the method that reads the file and fills an array with the available lines.</p>

<p>Here's my <code>Activity</code> where I create an Object <code>newwords</code> from the class <code>Words</code>, and then I want to call the <code>PlayWithRawFiles()</code> method from class <code>Words</code>.</p>

<pre><code>public class Swear_Activity extends Activity implements OnInitListener, OnClickListener {

    private Words newwords;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_swear);
    }
    public void onClick(View view){
        try {
            newwords.PlayWithRawFiles();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            System.out.println("greshka");
            e.printStackTrace();
        }
    }
}
</code></pre>

<p>now this is the class where i get the error</p>

<pre><code>public class Words{

    public Word[] wordsArray;
    private String locale = "de";

    public Words(String locale) {
        if (locale != null ) {
            this.locale = locale;
        }
    }

    Context c;
    public void PlayWithRawFiles() throws IOException  {
        String str="";
        StringBuffer buf = new StringBuffer();          
        int i = 0;
        InputStream is = c.getResources().openRawResource(R.raw.est);
        BufferedReader reader = null;
        try{
            if (is != null) reader = new BufferedReader(new InputStreamReader(is));
        }
        catch(Exception e) {
            System.out.println ("ss");
            e.printStackTrace();
        }

        if (is!=null) {                         
            while ((str = reader.readLine()) != null) { 
                Word wd = new Word(1,"str");
                this.wordsArray[i] = wd;
                i++;
            }               
        }       
        is.close();
    }
}
</code></pre>

<p>here is class Word</p>

<pre><code>public class Word {
    private int type;
    private String data;

    public Word(int type, String data){
        this.type = type;
        this.data=data;
    }

    public int getType(){
        return this.type;
    }
    public String getData(){
        return this.data;
    }
}
</code></pre>

<p>Here is the Stack Trace</p>

<blockquote>
  <p>07-10 13:28:58.558: E/AndroidRuntime(647): FATAL EXCEPTION: main</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647): java.lang.NullPointerException</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647): at de.android.swearapp.Swear_Activity.onClick(Swear_Activity.java:32)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at >android.view.View.performClick(View.java:2408)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at android.view.View$PerformClick.run(View.java:8816)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at android.os.Handler.handleCallback(Handler.java:587)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at android.os.Handler.dispatchMessage(Handler.java:92)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at android.os.Looper.loop(Looper.java:123)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at android.app.ActivityThread.main(ActivityThread.java:4627)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at java.lang.reflect.Method.invokeNative(Native Method)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at java.lang.reflect.Method.invoke(Method.java:521)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)</p>
  
  <p>07-10 13:28:58.558: E/AndroidRuntime(647):     at dalvik.system.NativeStart.main(Native Method)</p>
</blockquote>

<p>What have I done wrong? I'm really stuck at this one. Thank you in advance!</p>
