Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7632801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:43:06+00:00 2026-05-31T06:43:06+00:00

I am using this code to get the phonenumber of every contact but I

  • 0

I am using this code to get the phonenumber of every contact
but I get the following error :

03-10 19:52:44.925: E/AndroidRuntime(15954): FATAL EXCEPTION: main
03-10 19:52:44.925: E/AndroidRuntime(15954):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{contact.backup.alexander.fuchs/contact.backup.alexander.fuchs.App}:
android.database.CursorIndexOutOfBoundsException: Index -1 requested,
with a size of 1 03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.app.ActivityThread.access$1500(ActivityThread.java:117) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.os.Handler.dispatchMessage(Handler.java:99) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
android.os.Looper.loop(Looper.java:130) 03-10 19:52:44.925:
E/AndroidRuntime(15954): at
android.app.ActivityThread.main(ActivityThread.java:3691) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
java.lang.reflect.Method.invokeNative(Native Method) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
java.lang.reflect.Method.invoke(Method.java:507) 03-10 19:52:44.925:
E/AndroidRuntime(15954): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
dalvik.system.NativeStart.main(Native Method) 03-10 19:52:44.925:
E/AndroidRuntime(15954): Caused by:
android.database.CursorIndexOutOfBoundsException: Index -1 requested,
with a size of 1 03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.database.CursorWrapper.getString(CursorWrapper.java:135) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
contact.backup.alexander.fuchs.App.onCreate(App.java:85) 03-10
19:52:44.925: E/AndroidRuntime(15954): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-10 19:52:44.925: E/AndroidRuntime(15954): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
03-10 19:52:44.925: E/AndroidRuntime(15954): … 11 more

My code :

package contact.backup.alexander.fuchs;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentUris;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.provider.Contacts.Phones;
import android.provider.ContactsContract;

public class App extends Activity {
    /** Called when the activity is first created. */

    int i;
    int i2;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        util.deleteDir(new File("/data/data/contact.backup.alexander.fuchs/backup/"));
        new File("/data/data/contact.backup.alexander.fuchs/backup/").mkdirs(); 



        // get it 
        ContentResolver cr = getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);


        if (cur.getCount() > 0) {
            i = 0;
            i2 = 0;
        while (cur.moveToNext()) {
            String id = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts._ID));
        String name = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));


        // write
        try
        {
            new File("/data/data/contact.backup.alexander.fuchs/backup/"+String.valueOf(i)).mkdirs(); 

            FileWriter fstream = new FileWriter("/data/data/contact.backup.alexander.fuchs/backup/"+String.valueOf(i)+"/id.txt");
            BufferedWriter out = new BufferedWriter(fstream);
            out.write(id);
            //Close the output stream
            out.close();


            fstream = new FileWriter("/data/data/contact.backup.alexander.fuchs/backup/"+String.valueOf(i)+"/name.txt");
            out = new BufferedWriter(fstream);
            out.write(name);
            //Close the output stream
            out.close();





        }
        catch (Exception x)
        {

        }
        if (Integer.parseInt(cur.getString(
                cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
             Cursor pCur = cr.query(
            ContactsContract.CommonDataKinds.Phone.CONTENT_URI, 
            null, 
            ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", 
            new String[]{id}, null);

                String number = pCur.getString(
                        pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                while (pCur.moveToNext()) {
                    try
                    {
                    new File("/data/data/contact.backup.alexander.fuchs/backup/"+String.valueOf(id)).mkdirs(); 

                    FileWriter fstream = new FileWriter("/data/data/contact.backup.alexander.fuchs/backup/"+String.valueOf(id)+"/number.txt");
                    BufferedWriter out = new BufferedWriter(fstream);
                    out.write(number);
                    //Close the output stream
                    out.close();


                    }
                    catch(Exception x)
                    {

                    }
                    } 


            pCur.close();

        }
        i++;
        }


    }

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T06:43:07+00:00Added an answer on May 31, 2026 at 6:43 am
     private ArrayList<Map<String, String>> peopleList;
     private AutoCompleteTextView txtPhoneName;
        private SimpleAdapter mAdapter;
    

    //in oncreate

     txtPhoneName=(AutoCompleteTextView)findViewById(R.id.autoDeni);
    
    peopleList = new ArrayList<Map<String, String>>();
    PopulatePeopleList();
    
    
    mAdapter = new SimpleAdapter(this, peopleList, R.layout.row ,new String[] { "Name", "Phone"  }, new int[] { R.id.text1, R.id.text2  });
    
    txtPhoneName.setAdapter(mAdapter);
    
     public void PopulatePeopleList()
      {
    
     peopleList.clear();
    
    Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    
    while (people.moveToNext())
    {
    String contactName = people.getString(people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
    
    String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID));
    String hasPhone = people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
    
    if ((Integer.parseInt(hasPhone) > 0))
    {
    
    // You know have the number so now query it like this
    Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null,ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ contactId,null, null);
    while (phones.moveToNext()) {
    
    //store numbers and display a dialog letting the user select which.
    String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
    
    //String numberType = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));
    
    Map<String, String> mapa = new HashMap<String, String>();
    
    mapa.put("Name",contactName+"\n"+phoneNumber);
    mapa.put("Phone", phoneNumber);
    
    /* if(numberType.equals("0"))
    mapa.put("Type", "Work");
    else
    if(numberType.equals("1"))
    mapa.put("Type", "Home");
    else if(numberType.equals("2"))
    mapa.put("Type",  "Mobile");
    else
    mapa.put("Type", "Other");*/
    
    //Then add this map to the list.
    peopleList.add(mapa);
    }
    phones.close();
    }
    }
    people.close();
    
    startManagingCursor(people);
    }
    

    //this is what i get for getting all the contacts in the autocompletetextview here i will show u the row.xml that i am using in the simple adapter NOTE:in oncreate the current context IS NOT row.xml

    row xml:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
     <TextView 
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:padding="10dip" >
    
    
    </TextView>
    
    <TextView 
    android:id="@+id/text2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:padding="10dip" >
    
    
    </TextView>
    

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently, I'm using this code in order to get the contact name and the
After using this code to get my link to show me 3 database entrys
I am using this code to get the background image of a div .
I am currently using this code to get data from a URL: NSURL *url
I'm using this code for get all news: List<aspnet_News> allNews = context.aspnet_News.OrderByDescending(i => i.NewsId).ToList();
While using this code, i can't get any results... Ext.define('Teste.view.Main', { extend: 'Ext.Container', initialize:
I get the memberOf property for my user using this code: DirectorySearcher search =
In a BlackBerry application, I am using this code in order to get a
Using this jquery code: <a href=javascript:void(0) id=m1>Get Selected id's</a> jQuery(#m1).click( function() { var s;
Ok i am using this code to get the list of applications on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.