Wednesday, 15 May 2013

android - IllegalStateException while fetching contacts asynchronously -


When I tried to bring contacts into the ontet method using the following code,

 < Code> cursor C = getContentResolver (). Query (ContactsContract.Contacts.CONTENT_URI, blank, blank, blank, contactcontact.DISPLAY_NAME); If (c. Gatecount ()> gt; 0) {log. ("Number of contacts:", string.value (c. Gatecount ())); While (c.moveToNext ()) {Log.i ("contact", c.getString (c.getColumnIndex (contactsContract.Contacts.DISPLAY_NAME)); }}  

This worked. But when I moved the code to asyncTask-doInBackground, it is giving IllegalStateException here my code is

  secure ArrayList & lt; String & gt; DoInBackground (Zero ... Parameter) {Cursor C = mContext.getContentResolver (). Query (ContactsContract.Contacts.CONTENT_URI, blank, empty, blank, ContactsContract.Contacts.DISPLAY_NAME); ArrayList & LT; String & gt; X = new arreelist & lt; & Gt; (); If (c.getCount ()> gt; 0) {stringbilder sb = New stringbilder (); While (c.moveToNext ()) {sb.append (c.getString (c.getColumnIndex (ContactsContract.Contacts.DISPLAY_NAME)); X.add (sb.toString ()); Log.i ("contact", sb.toString ()); }} Return x; }  

Here's my log CAT output

  E / Android Rentaim: Fasl exception: AsyncTask # 1 java.lang.RuntimeException: doInBackground while executing a error android.os.AsyncTask on java.util.concurrent.FutureTask.setException (FutureTask.java on () $ 3.done (AsyncTask.java:299) java.util.concurrent.FutureTask $ Sync.innerSetException (FutureTask.java 273) to: 124) android.os.AsyncTask $ SerialExecutor $ 1.run on java.util.concurrent.FutureTask $ Sync.innerRun (FutureTask.java:307) java.util.concurrent.FutureTask.run (FutureTask.java : 137) (JavaklangkThreadkrun on java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:569) on java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1076) AsyncTask.java:230) (thru ADJAVA: 856) Reason: java.lang.IllegalStateException: Line 0, Colonel-1 could not be read from the cursor window. Make sure that the cursor is properly started before accessing data from it. android.database.CursorWindow.nativeGetString (Native Method android.database.CursorWindow.getString on android.database.CursorWrapper.getString) (CursorWindow.java:434) on android.database.AbstractWindowedCursor.getString (AbstractWindowedCursor.java:51) At (use the cursor. Java 14.14) akshara.xcontacts.adapters.ContactsListAdapter $ contactsLoader.doInBackground (contactsListAdapter.java:100) at akshara.xcontacts.adapters.ContactsListAdapter $ ContactsLoader.doInBackground (ContactsListAdapter.java:77) asyncTask on android.os $ 2.call java.util.concurrent.FutureTask $ Sync.innerRun on (AsyncTask.java:287) (FutureTask.java:305)  at java.util.concurrent.FutureTask 

. Run android.os.AsyncTask $ SerialExecutor $ 1.run on java.util.concurrent.ThreadPoolExecutor.runWorker on (AsyncTask.java:230) (FutureTask.java:137) (ThreadPoolExecutor.java:1076) Java.util.concurrent. $ Worker.run at ThreadPoolExecutor (Threadpool Exporter. Java / 696) at java.lang.Thread.run (Thread.Java: 856)

Can anyone tell me what is wrong with my code? / P>

To ensure mContext immediately before executing asyncTask

if not working Try:

Use ArrayList & lt; String & gt; X = new Arasuachi & lt; String & gt; ();

Instead of:

  ArrayList & lt; String & gt; X = new arreelist & lt; & Gt; ();  

No comments:

Post a Comment