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 8110143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:38:54+00:00 2026-06-06T01:38:54+00:00

am going to read 5- Contacts , So i get this code and go

  • 0

am going to read 5- Contacts , So i get this code and go smooth and no error occurred,
But when i add this two line for save the Name and contact to use them later , this exception appeared !!

this is the code :

    Cursor cursor = getContentResolver().query(
            ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
    while (cursor.moveToNext()) {
        String contactId = cursor.getString(cursor
                .getColumnIndex(ContactsContract.Contacts._ID));
        String hasPhone = cursor
                .getString(cursor
                        .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
        name = cursor.getString(cursor
                .getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

        // You know it has a number so now query it like this
        Cursor phones1 = getContentResolver().query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = "
                        + contactId, null, null);
        if (count > 5)
            break;
        while (phones1.moveToNext()) {
            phoneNumber = phones1
                    .getString(phones1
                            .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));


        }

        phones1.close();


        Toast.makeText(this,
                contactId + " __ " + name + " # :  " + phoneNumber,
                Toast.LENGTH_SHORT).show();
        Contact2[count] = name;
        Numbers2[count] = phoneNumber;
        count++;

    }

the two statements cause the exception !!

Contact2[count] = name;
Numbers2[count] = phoneNumber;

however the code go well without these statements .

this are the logcat window

06-15 18:00:02.745: I/ApplicationPackageManager(8639): cscCountry is not German : XEU
06-15 18:00:03.586: W/dalvikvm(8639): threadid=1: thread exiting with uncaught   exception (group=0x4001d560)
06-15 18:00:03.586: E/AndroidRuntime(8639): FATAL EXCEPTION: main
06-15 18:00:03.586: E/AndroidRuntime(8639): java.lang.IllegalStateException: Could not  execute method of the activity
06-15 18:00:03.586: E/AndroidRuntime(8639):     at  android.view.View$1.onClick(View.java:2154)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.view.View.performClick(View.java:2538)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.view.View$PerformClick.run(View.java:9152)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.os.Handler.handleCallback(Handler.java:587) 
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.os.Handler.dispatchMessage(Handler.java:92)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.os.Looper.loop(Looper.java:123)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.app.ActivityThread.main(ActivityThread.java:3687)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at java.lang.reflect.Method.invokeNative(Native Method)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at java.lang.reflect.Method.invoke(Method.java:507)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at dalvik.system.NativeStart.main(Native Method)
06-15 18:00:03.586: E/AndroidRuntime(8639): Caused by: java.lang.reflect.InvocationTargetException
06-15 18:00:03.586: E/AndroidRuntime(8639):     at java.lang.reflect.Method.invokeNative(Native Method)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at java.lang.reflect.Method.invoke(Method.java:507)
06-15 18:00:03.586: E/AndroidRuntime(8639):     at android.view.View$1.onClick(View.java:2149)
06-15 18:00:03.586: E/AndroidRuntime(8639):     ... 11 more
06-15 18:00:03.586: E/AndroidRuntime(8639): Caused by: java.lang.NullPointerException
06-15 18:00:03.586: E/AndroidRuntime(8639):     at oo.k.TestActivity.upload(TestActivity.java:156)

i just neeed to save the Contact result.

  • 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-06T01:38:56+00:00Added an answer on June 6, 2026 at 1:38 am

    It looks like you’re getting a Null Pointer Exception, probably because you haven’t initialized your arrays Contact2 and Numbers2.

    Contact2 = new String[5];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm trying to read contacts with this code but it only gets Contacts but
Is it okay to get a read-only collection from an aggregate without going through
I'm going nuts over this. I can write to a cookie, and then read
I've read all about this online but everything else was just overly complicated and
I am writing some Java code that is going to read in some data
My datagrid is not going to read any value from database, but just need
Here are my code:- //Sending mail if ($this->Session->read('Enrollment.personalinfo_language') == 'English') { $language = english;
First I've read loads of posts and sites that recommend going to http://silverlight.net/GetStarted/ to
I need to read a BLOB and store it in a byte[], before going
Going through Javascript documentation, I found the following two functions on a Javascript object

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.