title: AssetManager null pointer exception
body: <p>I'm getting a null pointer exception on the line marked with /<em>Here</em>/ in my code. I've spent about 2 hours looking up the AssetManager and how to use it, etc, but still can't figure out why it's null. I've called getAssets() by itself, from the context and from the resources but still I'm getting null. Can anyone help me out here? 
  Thanks.</p>
  
  <pre><code>package com.hamc17.CatFacts;
  
  import android.app.Activity;
  import android.content.Context;
  import android.content.res.AssetManager;
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.Button;
  import android.widget.Toast;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.Random;
  
  public class FactsActivity extends Activity{
  
  Context context;
  Resources res;
  
  @Override
  public void onCreate(Bundle savedInstanceBundle){
  
      super.onCreate(savedInstanceBundle);
  
      context = getApplicationContext();
      res = context.getResources();
  
      Button getFactButton = (Button) findViewById(R.id.getFactButton);
      getFactButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              Toast toastMessageOnClick = new Toast(FactsActivity.this);
              toastMessageOnClick.setText(getFact());
              if((toastMessageOnClick.toString()).length()&gt;50)
              {
                  toastMessageOnClick.setDuration(10);
              }
              else
              {
                  toastMessageOnClick.setDuration(Toast.LENGTH_LONG);
              }
              toastMessageOnClick.show();
          }
      });
  }
  
  
      String[] factArray = getFactsFromTextFile().split(";");
      private String getFactsFromTextFile(){
  /*Here*/ AssetManager assMan = context.getAssets();
          try{
              BufferedReader buff = new BufferedReader(new InputStreamReader(assMan.open("facts.txt")));
              String line;
              StringBuilder build = new StringBuilder();
              while((line = buff.readLine()) != null)
              {
                  build.append(line).append(System.getProperty("line.seperator"));
              }
              return build.toString();
          }
          catch (IOException e)
          {
              Toast toastMessage = new Toast(getApplicationContext());
              toastMessage.setText(e.toString() + "\n Whoops, there was an error! ");
              toastMessage.show();
              return "";
          }
          finally
          {
              try{
                  assMan.close();
              }
              catch (Exception e)
              {
                  //Whatever Trevor
              }
          }
      }
  
  private String getFact(){
  
      String randomFactString = "";
      int factCount = factArray.length;
  
      Random rng = new Random();
      int randomNum = rng.nextInt()*factCount;
  
      randomFactString = factArray[randomNum];
  
      return randomFactString;
  }
  </code></pre>
  
  <p>}</p>