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

  • Home
  • SEARCH
  • 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 8690411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:53:48+00:00 2026-06-12T23:53:48+00:00

Am developing a android application using phonegap(Cordova 2.0.0). I need the retrieve the device

  • 0

Am developing a android application using phonegap(Cordova 2.0.0). I need the retrieve the device contacts. I have tried with code given this doc

http://docs.phonegap.com/en/2.0.0/cordova_contacts_contacts.md.html#Contacts

my code as follows

$("#shareoptions3").live('click',function(){        

    var options = new ContactFindOptions();

    options.multiple  = true; 
    var fields = ["displayName","phoneNumbers"];//["displayName", "name","phoneNumbers"];
    navigator.contacts.find(fields, onContactSuccess, onContactError, options);
});

function onContactSuccess(contacts) {//alert(contacts.length);

    for (var i=0; i<contacts.length; i++) {
        // display phone numbers
        for (var j=0; j<contacts[i].phoneNumbers.length; j++) {
            alert("Type: " + contacts[i].phoneNumbers[j].type + "\n" + 
                "Value: "  + contacts[i].phoneNumbers[j].value + "\n" + 
                "Preferred: "  + contacts[i].phoneNumbers[j].pref);
        }
    }
};

// onError: Failed to get the contacts
//
function onContactError(contactError) {
    console.log('Error in getting contacts!');
}

I am getting message in Logcat like this :

Error in success callback: Contacts3 = TypeError: Cannot read property ‘length’ of null at file:///android_asset/www/JS/cordova-2.0.0.js:258

Please help me to sort out this problem.

  • 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-06-12T23:53:49+00:00Added an answer on June 12, 2026 at 11:53 pm

    One of your contact may not have a telephone number, and that is why you’ll get a null value instead of a phone number.

    So, in your for loop, one of the contacts[i].phoneNumbers.length wil generate an error.

    I suggest you to first check if the phoneNumbers is null or not, before displaying / alerting it, by using:

    if(contacts[i].phoneNumbers != null)
    

    In the end, you may try something like this:

    $("#shareoptions3").live('click',function(){        
    
        var options = new ContactFindOptions();
    
        options.multiple  = true; 
        var fields = ["displayName","phoneNumbers"];//["displayName", "name","phoneNumbers"];
        navigator.contacts.find(fields, onContactSuccess, onContactError, options);
    });
    
    function onContactSuccess(contacts) {//alert(contacts.length);
    
        for (var i=0; i<contacts.length; i++) {
    
            // display phone numbers
    
            if(contacts[i].phoneNumbers != null)  // Checking if not null
                for (var j=0; j<contacts[i].phoneNumbers.length; j++) {
                    alert("Type: " + contacts[i].phoneNumbers[j].type + "\n" + 
                        "Value: "  + contacts[i].phoneNumbers[j].value + "\n" + 
                        "Preferred: "  + contacts[i].phoneNumbers[j].pref);
                }
        }
    };
    
    // onError: Failed to get the contacts
    //
    function onContactError(contactError) {
        console.log('Error in getting contacts!');
    }
    

    Hope this helps, let me know if this works for you.

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

Sidebar

Related Questions

I am developing an android app using phonegap (cordova-2.1.0). My MainActivity.java code is as
I am developing an Android application using Phonegap . I need to make the
I am developing an app using phonegap for Android. I want this mobile application
hi i am developing an android application using phonegap and i have come across
I am developing application using phonegap in eclipse for android .I have created folder
I am developing an application for Android using PhoneGap (Cordova 1.6.1). My application crashes
I am developing an application using phonegap for both ios and android. My application
I am currently developing an android application using eclipse and I already have a
I am developing an android mobile application using eclipse. I need a database that
I am developing an application using Android SDK. In this application I am facing

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.