title: getContentResolver with AsyncTask
body: <p>I am new to android, and so learning AsyncTask library.
  I want to perform operation on user contacts list in AsyncTask. Because it is a long process, I don't want user to be wait until it finish. But whenever I run it, it close my application, Without calling getContentResolver method, my AsyncTask methods are working fine.
  I don't know what is the issue with my getContentResolver method.</p>
  
  <p>My AsyncTask file is,</p>
  
  <pre><code>public class clsAsyncTask extends AsyncTask&lt;TextView, String, Boolean&gt; {
  
      TextView txtView;
      Boolean finalStatus = false;
      @Override
      protected Boolean doInBackground(TextView... params) {
  
          if(params.length &gt; 0){
              txtView = params[0];
              saveContacts contacts = new saveContacts("");
              contacts.onHandleIntent(new Intent());
              publishProgress("Step 2 cleared");
              finalStatus = true;
          }
          return finalStatus;
      }
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      @Override
      protected void onPostExecute(Boolean aBoolean) {
          if(aBoolean){
              publishProgress("All cleared");
          }else{
              publishProgress("Error accured");
          }
      }
  
      @Override
      protected void onProgressUpdate(String... values) {
          txtView.setText(values[0]);
      }
  }
  </code></pre>
  
  <p>My getContentResolver file is,</p>
  
  <pre><code>public class saveContacts extends IntentService {
  
      public saveContacts(String name) {
          super(name);
      }
  
      @Override
      protected void onHandleIntent(Intent intent) {
          StringBuffer sb = new StringBuffer();
          sb.append("......Contact Details.....");
  
          String name = "";
          String phoneNumber="";
          String emailId = "";
          Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,null,null, null);
          sb.append("total = " + phones.getCount());
          while (phones.moveToNext())
          {
              name=phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
              phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
              sb.append("\nEmail: " + name + " phoneNumber: " + phoneNumber);
  
          }
          phones.close();
  
      }
  }
  </code></pre>
  
  <p>And my main activity calling Async method like below,</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  
      TextView txtView;
      clsAsyncTask _AsyncTaskWorker;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          txtView = (TextView) findViewById(R.id.txt_view);
  
          txtView.setText("Execution start");
          _AsyncTaskWorker = new clsAsyncTask();
          _AsyncTaskWorker.execute(txtView);
      }
  }
  </code></pre>
  
  <p>Logcat in error part, it shows me like below,</p>
  
  <pre><code>07-11 09:02:24.630      664-705/? E/ElectronBeam﹕ Can not update rotation!
  07-11 09:02:24.946      664-705/? E/ElectronBeam﹕ Can not update rotation!
  07-11 09:02:26.295    4384-4384/? E/InitDefaultSoftInfo﹕ i=1defaultresolveinfo.size():2
  07-11 09:02:26.295    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.327      735-735/? E/KeyguardUpdateMonitor﹕ Object tried to add another callback
      java.lang.Exception: Called by
              at com.android.keyguard.KeyguardUpdateMonitor.registerCallback(KeyguardUpdateMonitor.java:1176)
              at com.android.keyguard.KeyguardSelectorView.onResume(KeyguardSelectorView.java:397)
              at com.android.keyguard.KeyguardHostView.onScreenTurnedOn(KeyguardHostView.java:1311)
              at com.android.keyguard.KeyguardViewManager.onScreenTurnedOn(KeyguardViewManager.java:576)
              at com.android.keyguard.KeyguardViewMediator.handleNotifyScreenOn(KeyguardViewMediator.java:1933)
              at com.android.keyguard.KeyguardViewMediator.access$2500(KeyguardViewMediator.java:132)
              at com.android.keyguard.KeyguardViewMediator$4.handleMessage(KeyguardViewMediator.java:1539)
              at android.os.Handler.dispatchMessage(Handler.java:110)
              at android.os.Looper.loop(Looper.java:193)
              at android.app.ActivityThread.main(ActivityThread.java:5341)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:830)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:646)
              at dalvik.system.NativeStart.main(Native Method)
  07-11 09:02:26.343    4384-4384/? E/InitDefaultSoftInfo﹕ i=2defaultresolveinfo.size():3
  07-11 09:02:26.343    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.351    4384-4384/? E/InitDefaultSoftInfo﹕ i=3defaultresolveinfo.size():4
  07-11 09:02:26.351    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.356      664-664/? E/﹕ Could not open '/data/data/hotplug/cmd'
  07-11 09:02:26.356      664-664/? E/﹕ error : 2, No such file or directory
  07-11 09:02:26.440    4384-4384/? E/InitDefaultSoftInfo﹕ i=4defaultresolveinfo.size():5
  07-11 09:02:26.440    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.700    4384-4384/? E/InitDefaultSoftInfo﹕ i=6defaultresolveinfo.size():7
  07-11 09:02:26.700    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.814    4384-4384/? E/InitDefaultSoftInfo﹕ i=7defaultresolveinfo.size():8
  07-11 09:02:26.814    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:26.944    143-30185/? E/AudioMTKHardware﹕ setCommonParameters() still have param.size() = 1, remain param = "screen_state=on"
  07-11 09:02:28.333      664-664/? E/RemoteViews﹕ ANR Warning,RemoteViews can only be used once ,if not ,it may cause ANR in hosts such as Laucher,SystemUI. keys for search &lt;ANR Exception MSG   History&gt;
  07-11 09:02:28.802     858-1274/? E/CellLocation﹕ create GsmCellLocation
  07-11 09:02:29.049     858-1274/? E/CellLocation﹕ create GsmCellLocation
  07-11 09:02:29.514     973-1156/? E/ActivityThread﹕ Failed to find provider info for com.gionee.account
  07-11 09:02:30.202  16221-16221/? E/PhotosPlugin﹕ Loading PhotosPlugin
  07-11 09:02:31.962      143-516/? E/﹕ AudioCloseDumpPCMFile file== NULL
  07-11 09:02:31.962      143-516/? E/﹕ AudioCloseDumpPCMFile file== NULL
  07-11 09:02:31.962      143-516/? E/﹕ AudioCloseDumpPCMFile file== NULL
  07-11 09:02:31.962      143-516/? E/﹕ AudioCloseDumpPCMFile file== NULL
  07-11 09:02:32.476  16165-16241/keval.asynctask E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #1
      Process: keval.asynctask, PID: 16165
      java.lang.RuntimeException: An error occured while executing doInBackground()
              at android.os.AsyncTask$3.done(AsyncTask.java:300)
              at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
              at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
              at java.util.concurrent.FutureTask.run(FutureTask.java:242)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:841)
       Caused by: java.lang.NullPointerException
              at android.content.ContextWrapper.getContentResolver(ContextWrapper.java:99)
              at keval.asynctask.saveContacts.onHandleIntent(saveContacts.java:26)
              at keval.asynctask.clsAsyncTask.doInBackground(clsAsyncTask.java:24)
              at keval.asynctask.clsAsyncTask.doInBackground(clsAsyncTask.java:14)
              at android.os.AsyncTask$2.call(AsyncTask.java:288)
              at java.util.concurrent.FutureTask.run(FutureTask.java:237)
              at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
              at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
              at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
              at java.lang.Thread.run(Thread.java:841)
  07-11 09:02:32.501  16165-16165/keval.asynctask E/﹕ appName=keval.asynctask, acAppName=/system/bin/surfaceflinger
  07-11 09:02:32.501  16165-16165/keval.asynctask E/﹕ 0
  07-11 09:02:32.501  16165-16165/keval.asynctask E/﹕ appName=keval.asynctask, acAppName=/system/bin/surfaceflinger
  07-11 09:02:32.501  16165-16165/keval.asynctask E/﹕ 0
  07-11 09:02:32.889      664-684/? E/﹕ Could not open '/data/data/hotplug/cmd'
  07-11 09:02:32.889      664-684/? E/﹕ error : 2, No such file or directory
  07-11 09:02:33.077    4384-4384/? E/InitDefaultSoftInfo﹕ i=1defaultresolveinfo.size():2
  07-11 09:02:33.077    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.093    4384-4384/? E/InitDefaultSoftInfo﹕ i=2defaultresolveinfo.size():3
  07-11 09:02:33.093    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.095    4384-4384/? E/InitDefaultSoftInfo﹕ i=3defaultresolveinfo.size():4
  07-11 09:02:33.095    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.096    4384-4384/? E/InitDefaultSoftInfo﹕ i=4defaultresolveinfo.size():5
  07-11 09:02:33.096    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.141    4384-4384/? E/InitDefaultSoftInfo﹕ i=6defaultresolveinfo.size():7
  07-11 09:02:33.141    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.163    4384-4384/? E/InitDefaultSoftInfo﹕ i=7defaultresolveinfo.size():8
  07-11 09:02:33.163    4384-4384/? E/InitDefaultSoftInfo﹕ best != null
  07-11 09:02:33.496      664-944/? E/﹕ Could not open '/data/data/hotplug/cmd'
  07-11 09:02:33.496      664-944/? E/﹕ error : 2, No such file or directory
  07-11 09:02:35.064  16307-16323/? E/chromium_android_linker﹕ UseSharedRelro: Could not use shared RELRO for libchrome.so: No pages were swapped into RELRO ashmem
  07-11 09:02:35.131  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.131  16307-16323/? E/﹕ 0
  07-11 09:02:35.131  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.131  16307-16323/? E/﹕ 0
  07-11 09:02:35.229    1003-1003/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid parameter app
  07-11 09:02:35.229    1003-1003/? E/NetworkScheduler.SchedulerReceiver﹕ Invalid package name : Perhaps you didn't include a PendingIntent in the extras?
  07-11 09:02:35.300  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.301  16307-16323/? E/﹕ 0
  07-11 09:02:35.301  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.301  16307-16323/? E/﹕ 0
  07-11 09:02:35.325  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.325  16307-16323/? E/﹕ 0
  07-11 09:02:35.325  16307-16323/? E/﹕ appName=com.android.chrome:privileged_process0, acAppName=/system/bin/surfaceflinger
  07-11 09:02:35.325  16307-16323/? E/﹕ 0
  07-11 09:02:36.016  16370-16370/? E/﹕ appName=com.google.android.apps.magazines, acAppName=/system/bin/surfaceflinger
  07-11 09:02:36.016  16370-16370/? E/﹕ 0
  07-11 09:02:36.016  16370-16370/? E/﹕ appName=com.google.android.apps.magazines, acAppName=/system/bin/surfaceflinger
  07-11 09:02:36.016  16370-16370/? E/﹕ 0
  07-11 09:02:36.791  16422-16440/? E/NativeCrypto﹕ ssl=0x607e57a8 cert_verify_callback x509_store_ctx=0x610ad8c0 arg=0x0
  07-11 09:02:36.791  16422-16440/? E/NativeCrypto﹕ ssl=0x607e57a8 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
  07-11 09:02:36.813  16470-16470/? E/dalvikvm﹕ Could not find class 'com.amazon.device.messaging.ADM', referenced from method com.appboy.Appboy.&lt;init&gt;
  07-11 09:02:37.291     664-1595/? E/ActivityManager﹕ Service ServiceRecord{42d9f2b0 u0 com.google.android.youtube/com.google.android.apps.youtube.app.offline.transfer.OfflineTransferService} in process ProcessRecord{42c8a980 15786:com.google.android.youtube/u0a91} not same as in map: null
  07-11 09:02:37.348  16470-16542/? E/NativeCrypto﹕ ssl=0x62875cc0 cert_verify_callback x509_store_ctx=0x6274a940 arg=0x0
  07-11 09:02:37.348  16470-16542/? E/NativeCrypto﹕ ssl=0x62875cc0 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
  07-11 09:02:37.453    1003-1003/? E/AuthorizationBluetoothService﹕ Proximity feature is not enabled.
  07-11 09:02:37.456  16470-16532/? E/NativeCrypto﹕ ssl=0x629948f8 cert_verify_callback x509_store_ctx=0x623a1940 arg=0x0
  07-11 09:02:37.456  16470-16532/? E/NativeCrypto﹕ ssl=0x629948f8 cert_verify_callback calling verifyCertificateChain authMethod=RSA
  07-11 09:02:37.482  16470-16529/? E/NativeCrypto﹕ ssl=0x628abbb0 cert_verify_callback x509_store_ctx=0x6203e940 arg=0x0
  07-11 09:02:37.483  16470-16529/? E/NativeCrypto﹕ ssl=0x628abbb0 cert_verify_callback calling verifyCertificateChain authMethod=RSA
  07-11 09:02:37.526  16294-16294/? E/dalvikvm﹕ Could not find class 'android.telecom.TelecomManager', referenced from method com.google.android.gms.wearable.service.y.a
  07-11 09:02:37.603     858-2870/? E/MDM﹕ [67] b.run: Couldn't connect to Google API client: ConnectionResult{statusCode=API_UNAVAILABLE, resolution=null}
  07-11 09:02:38.568  16572-16572/? E/dalvikvm﹕ Could not find class 'android.app.Notification$Action$Builder', referenced from method b.a
  07-11 09:02:38.584  16572-16572/? E/dalvikvm﹕ Could not find class 'al', referenced from method b.a
  07-11 09:02:38.586  16572-16572/? E/dalvikvm﹕ Could not find class 'an', referenced from method b.a
  07-11 09:02:38.592  16572-16572/? E/dalvikvm﹕ Could not find class 'android.app.RemoteInput[]', referenced from method b.a
  07-11 09:02:38.871  16572-16572/? E/WifiManager﹕ mWifiServiceMessenger == null
  07-11 09:02:39.316  16572-16572/? E/WifiManager﹕ mWifiServiceMessenger == null
  07-11 09:02:42.352  16422-16422/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
  07-11 09:02:42.366  16422-16663/? E/ActivityThread﹕ Failed to find provider info for com.facebook.katana.provider.AttributionIdProvider
  07-11 09:02:42.546  16422-16439/? E/NativeCrypto﹕ ssl=0x607e3ed0 cert_verify_callback x509_store_ctx=0x60f6f940 arg=0x0
  07-11 09:02:42.547  16422-16439/? E/NativeCrypto﹕ ssl=0x607e3ed0 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_ECDSA
  07-11 09:02:58.108    143-17153/? E/AudioMTKHardware﹕ setCommonParameters() still have param.size() = 1, remain param = "screen_state=off"
  07-11 09:02:59.036     973-1156/? E/ActivityThread﹕ Failed to find provider info for com.gionee.account
  07-11 09:03:00.337      664-664/? E/RemoteViews﹕ ANR Warning,RemoteViews can only be used once ,if not ,it may cause ANR in hosts such as Laucher,SystemUI. keys for search &lt;ANR Exception MSG   History&gt;
  07-11 09:03:03.056      735-735/? E/KeyguardHostView﹕ KeyguardHostView()
  </code></pre>
  
  <p>I have added all permissions for internet and contact reading in manifest file.</p>
  
  <p>Please tell me what changes I need to make to make it work.</p>
  
  <p>Thank you.</p>