title: NullPointerException in Async onPostExecute
body: <p>I'm calling MainActivity function sendToServer(arguments) in Retriver.java class, this function works fine when I'm working in mainactivity class. But when I call it from retriver.java i get nullPointExceltion</p>
  
  <p>Logcat:</p>
  
  <pre><code>12-29 02:24:07.772: E/AndroidRuntime(12958): FATAL EXCEPTION: main
  12-29 02:24:07.772: E/AndroidRuntime(12958): Process: com.example.osc, PID: 12958
  12-29 02:24:07.772: E/AndroidRuntime(12958): java.lang.NullPointerException
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at com.example.osc.MainActivity$AsyncCreateUser.onPostExecute(MainActivity.java:340)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at com.example.osc.MainActivity$AsyncCreateUser.onPostExecute(MainActivity.java:1)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.os.AsyncTask.finish(AsyncTask.java:632)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.os.Handler.dispatchMessage(Handler.java:102)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.os.Looper.loop(Looper.java:136)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at java.lang.reflect.Method.invoke(Method.java:515)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  12-29 02:24:07.772: E/AndroidRuntime(12958):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>When I change getApplicationContext() to MainActivity.this it still gives error and logcat reslut is this.</p>
  
  <pre><code>12-29 02:43:09.829: E/AndroidRuntime(20558): FATAL EXCEPTION: main
  12-29 02:43:09.829: E/AndroidRuntime(20558): Process: com.example.osc, PID: 20558
  12-29 02:43:09.829: E/AndroidRuntime(20558): java.lang.NullPointerException
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.content.ContextWrapper.getResources(ContextWrapper.java:89)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.view.ContextThemeWrapper.getResources(ContextThemeWrapper.java:78)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.widget.Toast.&lt;init&gt;(Toast.java:93)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.widget.Toast.makeText(Toast.java:241)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at com.example.osc.MainActivity$AsyncCreateUser.onPostExecute(MainActivity.java:340)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at com.example.osc.MainActivity$AsyncCreateUser.onPostExecute(MainActivity.java:1)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.os.AsyncTask.finish(AsyncTask.java:632)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.os.Handler.dispatchMessage(Handler.java:102)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.os.Looper.loop(Looper.java:136)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at android.app.ActivityThread.main(ActivityThread.java:5017)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at java.lang.reflect.Method.invokeNative(Native Method)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at java.lang.reflect.Method.invoke(Method.java:515)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
  12-29 02:43:09.829: E/AndroidRuntime(20558):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>in Retriver.java</p>
  
  <pre><code> if (c.moveToFirst()) {
               sender_name = c.getString(c.getColumnIndexOrThrow("Chidname"));
               //sender_name = c.getString(c.getColumnIndex("senderName"));
               MainActivity obj = new MainActivity();
               if(
               obj.sendToServer(c.getString(c.getColumnIndexOrThrow("Chidname")),
                       c.getString(c.getColumnIndexOrThrow("Chidname")),
                       c.getString(c.getColumnIndexOrThrow("ChildAge")),
                       c.getString(c.getColumnIndexOrThrow("ChildGender")),
                       c.getString(c.getColumnIndexOrThrow("ChildAddress")),
                       c.getString(c.getColumnIndexOrThrow("Sendername")),
                       c.getString(c.getColumnIndexOrThrow("SenderEmail")),
                       c.getString(c.getColumnIndexOrThrow("SenderSimNo")),
                       c.getString(c.getColumnIndexOrThrow("SenderContact")),
                       c.getString(c.getColumnIndexOrThrow("Longitude")),
                       c.getString(c.getColumnIndexOrThrow("Latitude")),
                       "get this later")){
                   String deleteRecored = "DELETE FROM tblOSC WHERE _Id="+c.getString(c.getColumnIndexOrThrow("_Id"));
                   db.execSQL(deleteRecored);
               }
           }
  
           c.close();
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>public boolean sendToServer(String cpp, String cn,String ca,String cg, String cadd,String sn,String se,
          String ssn, String sp, String log, String lat, String cpis) {
      UserDetailsTable userDetail = new UserDetailsTable(cpp,
              cn, ca,
              cg,
              cadd, sn, se,
              sn, sp, log,
              lat, cpis);
      new AsyncCreateUser().execute(userDetail);
      return SENT_TO_SERVER_FLAG;
  }
  
  protected class AsyncCreateUser extends
          AsyncTask&lt;UserDetailsTable, Void, Void&gt; {
  
      @Override
      protected Void doInBackground(UserDetailsTable... params) {
  
          RestAPI api = new RestAPI();
          try {
  
              api.CreateNewAccount(params[0].getchildPhotoPath(),
                      params[0].getchildName(), params[0].getchildAge(),
                      params[0].getchildGender(),
                      params[0].getchildAddress(), params[0].getsenderName(),
                      params[0].getsenderCellPhone(),
                      params[0].getsenderMobile(),
                      params[0].getsenderEmail(), params[0].getlongitude(),
                      params[0].getlattitude(),
                      params[0].childPhotoImageString);
  
          } catch (Exception e) {
              // TODO Auto-generated catch block
              Log.d("AsyncCreateUser", e.getMessage());
  
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
  
          SENT_TO_SERVER_FLAG = true;
          Toast.makeText(getApplicationContext(),"sent to PEF", Toast.LENGTH_LONG).show();
      }
  
  }
  </code></pre>