title: openFileOutput not working properly inside a singleton class - ideas/workarounds?
body: <p>As a novice Android developer, I've faced a bit strange problem. I want to create a class, which methods other classes-activities-whatever could use for working with files in some special way. Let`s say for simplicity we would be logging some stuff. If I do following within an activity (in OnClick listener for example), everything works just fine:</p>
  
  <pre><code>FileOutputStream fOut = openFileOutput("somefile", MODE_PRIVATE);
  OutputStreamWriter osw = new OutputStreamWriter(fOut);
  osw.write("Very important foobar");
  osw.flush();
  osw.close();
  </code></pre>
  
  <p>But when I try to enclose that into some class and create singleton like that:</p>
  
  <pre><code>public class Logger extends BaseActivity {
  //BaseActivity is the "init" class which extends Activity
  
  public static final Logger INSTANCE = new Logger();
  private Logger() { 
  // singleton
  }
  
  public boolean doLog (String whatToLog) {
   try {
       FileOutputStream fOut = openFileOutput("somefile", MODE_PRIVATE);
   OutputStreamWriter osw = new OutputStreamWriter(fOut);
   osw.write(whatToLog);
   osw.flush();
   osw.close(); }
       catch (IOException ioe) { ioe.printStackTrace(); }  
       return true; }
  </code></pre>
  
  <p>and call it from other activity like that</p>
  
  <pre><code>Logger.INSTANCE.doLog("foobar");  
  </code></pre>
  
  <p>app chrashes with NullPointerException (at line with openFileOutput). I suppose it`s because of improper use of singleton/activity here and now rewriting the code to run as a service. But maybe there are some better ideas to solve an issue? Or some workarounds? </p>
  
  <p>Thanks for your contributions in advance!</p>