title: Null pointer exception in CursorLoader constructor
body: <p>I'm having some difficulty debugging a null pointer exception.</p>
  
  <pre><code>E/AndroidRuntime( 1760): java.lang.RuntimeException: Unable to instantiate application edu.lafayette.cs.geology.GeoDatabase: java.lang.NullPointerException
  
  ...
  
  E/AndroidRuntime( 1760): Caused by: java.lang.NullPointerException
  E/AndroidRuntime( 1760):    at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:101)
  E/AndroidRuntime( 1760):    at android.content.Loader.&lt;init&gt;(Loader.java:85)
  E/AndroidRuntime( 1760):    at android.content.AsyncTaskLoader.&lt;init&gt;(AsyncTaskLoader.java:90)
  E/AndroidRuntime( 1760):    at android.content.CursorLoader.&lt;init&gt;(CursorLoader.java:113)
  E/AndroidRuntime( 1760):    at edu.lafayette.cs.geology.GeoDatabase.createLoader(GeoDatabase.java:123)
  </code></pre>
  
  <p>Here is the relevant method createLoader in my code.</p>
  
  <pre><code>private CursorLoader createLoader(int id) {
      Uri tableUri;
      String[] projection;
  
      // Set the URI to query depending on the id of this loader.
      switch (id) {
      case LOCAL_FOLDER_LOADER:
          tableUri = LocalProvider.CONTENT_URI_FOLDER;
          projection = Folder.COLUMNS;
          break;
      case LOCAL_BEDDING_LOADER:
          tableUri = LocalProvider.CONTENT_URI_BEDDING;
          projection = Bedding.COLUMNS;
          break;
      case LOCAL_CONTACT_LOADER:
          tableUri = LocalProvider.CONTENT_URI_CONTACT;
          projection = Contact.COLUMNS;
          break;
      case LOCAL_FAULT_LOADER:
          tableUri = LocalProvider.CONTENT_URI_FAULT;
          projection = Fault.COLUMNS;
          break;
      case LOCAL_JOINT_SET_LOADER:
          tableUri = LocalProvider.CONTENT_URI_JOINT_SET;
          projection = JointSet.COLUMNS;
          break;
      default:
          throw new IllegalArgumentException("Unknown cursor loader id");
      }
  
      // Load up that cursor loader. Next, onLoadComplete is called.
      Log.d("createLoader", ""+tableUri);
      Log.d("createLoader", ""+projection);
      Log.d("createLoader", ""+this);
      CursorLoader cursorLoader = new CursorLoader(this, tableUri,
              projection, null, null, null);
      Log.d("createLoader", "statement reached");
      cursorLoader.registerListener(id, this);
      return cursorLoader;
  }
  </code></pre>
  
  <p>Line 125 is the one calling the CursorLoader constructor, in between the log statements. The log shows that <code>tableUri</code>, <code>projection</code>, and of course <code>this</code> are not null. The "statement reached" call is never reached. The rest of the nulls in the constructor call are supposed to be there, and they are <a href="http://developer.android.com/reference/android/content/CursorLoader.html#CursorLoader%28android.content.Context,%20android.net.Uri,%20java.lang.String%5b%5d,%20java.lang.String,%20java.lang.String%5b%5d,%20java.lang.String%29" rel="nofollow">specified in the API</a>. I can change the constructor call to use string literals and arrays instead of those three nulls, and the same exception is thrown. Anyone know what's up?</p>
  
  <p>I'd love to check out the CursorLoader source for clues, but Google has not released the source for the classes in API level 12 of this "open source" project.</p>