android - getContentResolver with AsyncTask -


i new android, , learning asynctask library. want perform operation on user contacts list in asynctask. because long process, don't want user wait until finish. whenever run it, close application, without calling getcontentresolver method, asynctask methods working fine. don't know issue getcontentresolver method.

my asynctask file is,

public class clsasynctask extends asynctask<textview, string, boolean> {      textview txtview;     boolean finalstatus = false;     @override     protected boolean doinbackground(textview... params) {          if(params.length > 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]);     } } 

my getcontentresolver file is,

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();      } } 

and main activity calling async method below,

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);     } } 

logcat in error part, shows me below,

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 add callback     java.lang.exception: called             @ com.android.keyguard.keyguardupdatemonitor.registercallback(keyguardupdatemonitor.java:1176)             @ com.android.keyguard.keyguardselectorview.onresume(keyguardselectorview.java:397)             @ com.android.keyguard.keyguardhostview.onscreenturnedon(keyguardhostview.java:1311)             @ com.android.keyguard.keyguardviewmanager.onscreenturnedon(keyguardviewmanager.java:576)             @ com.android.keyguard.keyguardviewmediator.handlenotifyscreenon(keyguardviewmediator.java:1933)             @ com.android.keyguard.keyguardviewmediator.access$2500(keyguardviewmediator.java:132)             @ com.android.keyguard.keyguardviewmediator$4.handlemessage(keyguardviewmediator.java:1539)             @ android.os.handler.dispatchmessage(handler.java:110)             @ android.os.looper.loop(looper.java:193)             @ android.app.activitythread.main(activitythread.java:5341)             @ java.lang.reflect.method.invokenative(native method)             @ java.lang.reflect.method.invoke(method.java:515)             @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:830)             @ com.android.internal.os.zygoteinit.main(zygoteinit.java:646)             @ 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/﹕ 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 used once ,if not ,it may cause anr in hosts such laucher,systemui. keys search <anr exception msg   history> 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 find provider info 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: error occured while executing doinbackground()             @ android.os.asynctask$3.done(asynctask.java:300)             @ java.util.concurrent.futuretask.finishcompletion(futuretask.java:355)             @ java.util.concurrent.futuretask.setexception(futuretask.java:222)             @ java.util.concurrent.futuretask.run(futuretask.java:242)             @ android.os.asynctask$serialexecutor$1.run(asynctask.java:231)             @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1112)             @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:587)             @ java.lang.thread.run(thread.java:841)      caused by: java.lang.nullpointerexception             @ android.content.contextwrapper.getcontentresolver(contextwrapper.java:99)             @ keval.asynctask.savecontacts.onhandleintent(savecontacts.java:26)             @ keval.asynctask.clsasynctask.doinbackground(clsasynctask.java:24)             @ keval.asynctask.clsasynctask.doinbackground(clsasynctask.java:14)             @ android.os.asynctask$2.call(asynctask.java:288)             @ 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/﹕ 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/﹕ 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: not use shared relro libchrome.so: no pages swapped 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 didn't include pendingintent in 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﹕ not find class 'com.amazon.device.messaging.adm', referenced method com.appboy.appboy.<init> 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 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 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﹕ not find class 'android.telecom.telecommanager', referenced 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 google api client: connectionresult{statuscode=api_unavailable, resolution=null} 07-11 09:02:38.568  16572-16572/? e/dalvikvm﹕ not find class 'android.app.notification$action$builder', referenced method b.a 07-11 09:02:38.584  16572-16572/? e/dalvikvm﹕ not find class 'al', referenced method b.a 07-11 09:02:38.586  16572-16572/? e/dalvikvm﹕ not find class 'an', referenced method b.a 07-11 09:02:38.592  16572-16572/? e/dalvikvm﹕ not find class 'android.app.remoteinput[]', referenced 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 find provider info com.facebook.katana.provider.attributionidprovider 07-11 09:02:42.366  16422-16663/? e/activitythread﹕ failed find provider info 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 find provider info com.gionee.account 07-11 09:03:00.337      664-664/? e/remoteviews﹕ anr warning,remoteviews can used once ,if not ,it may cause anr in hosts such laucher,systemui. keys search <anr exception msg   history> 07-11 09:03:03.056      735-735/? e/keyguardhostview﹕ keyguardhostview() 

i have added permissions internet , contact reading in manifest file.

please tell me changes need make make work.

thank you.

you're getting npe (aka nullpointerexception) because you're manually creating intentservice bad thing: savecontacts contacts = new savecontacts("");

here's tutorial on using intentservices.

or in case, makes sense move code out of onhandleintent , put directly doinbackground.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -