Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem on making .csv of contact list:android
    text
    copied!<p>I want to make .csv file of "contact name" and corresponding "contact no." but when i run the code following below given error occurs pls. see my code below and suggest me where i am wrong . means i have two columns one is name and second is contact no and values should be showh below that coloumn.so pls see my code .<strong>i am new in android and java</strong>.</p> <pre><code>public class contactlist extends Activity { static String name; static int count; static int countno; File file = null ; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ContentResolver cr = getContentResolver(); Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); if (cur.getCount() &gt; 0) { while (cur.moveToNext()) { String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); //error on below line String phoneno = cur.getString(cur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); cur.close(); String columnString = "\"PersonName\",\"phoneno\""; String dataString = null; dataString = "\"" + name +"\",\"" + phoneno + "\""; Log.i("saurabh",dataString); String combinedString = columnString + "\n" + dataString; File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { File dir = new File (root.getAbsolutePath() + "/PersonData"); dir.mkdirs(); file = new File(dir, "Data.csv"); FileOutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } try { out.write(combinedString.getBytes()); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } } } } } </code></pre> <p>error is....</p> <pre><code> 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): Caused by: java.lang.IllegalStateException: get field slot from row 0 col -1 failed 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.database.CursorWindow.getString_native(Native Method) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.database.CursorWindow.getString(CursorWindow.java:329) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:49) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.database.CursorWrapper.getString(CursorWrapper.java:135) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at contactlist.pkg.contactlist.onCreate(contactlist.java:83) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 07-28 16:09:56.758: ERROR/AndroidRuntime(27597): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload