I,m trying to read all contacts from phone and try to sort the contact names, but calling this method Arrays.sort(mystring, String.CASE\_INSENSITIVE\_ORDER) causes fatal exception.

I don't know what the problem is..? 
Is there any other way to sort an String array in android(java)

```
public class ContactActivity extends Activity {

/**
 * @param args
 */
public static HashMap<String, String> myHash = new HashMap<String, String>();
public static String[] mystring = new String[10000];
protected static int i = 0;
protected Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.contacts_screen);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    //*************************************************
    getContactNumbers(this);
    Log.i("Aravinth", "...before sorting....");
    Arrays.sort(mystring, String.CASE_INSENSITIVE_ORDER);
    //*******************************************************

    final ListView contactLV = (ListView)findViewById(R.id.contactsListView);
    MyListAdapter listViewAdapter = new MyListAdapter(this,R.layout.list_items,myHash,mystring);
    contactLV.setAdapter(listViewAdapter);
    /*
    Arrays.sort(contactData);
    for(int i =0;i<contactData.length;i++)
    {
        Log.d("Aravinth",contactData[i]);
    }
    */
}

public static void getContactNumbers(Context context) {
    String contactNumber = null;
    String nameOfContact = null;
    Uri imageUri;
    int i = 0;

    ContentResolver cr = context.getContentResolver();
    Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI, null,null, null, null);
        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(BaseColumns._ID));
                nameOfContact = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));

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

                    while (phones.moveToNext()) {
                        if(phones.getInt(phones.getColumnIndex(Phone.TYPE)) == Phone.TYPE_MOBILE)
                        {
                            contactNumber = phones.getString(phones.getColumnIndex(Phone.NUMBER));
                            mystring[i] = nameOfContact;
                            myHash.put(nameOfContact, nameOfContact);
                            Log.i("Aravinth", "...Contact Name ...." + mystring[i] + "...contact Number..." + contactNumber);
                        }
                    }
                    phones.close();
                }
                i++;
            }
        }// end of contact name cursor
        cur.close();
}

```

}

here is the log

```
08-03 00:45:25.247: I/Aravinth(676): ...before sorting....
08-03 00:45:25.267: D/AndroidRuntime(676): Shutting down VM
08-03 00:45:25.267: W/dalvikvm(676): threadid=1: thread exiting with uncaught exception (group=0x40a9b210)
08-03 00:45:25.287: E/AndroidRuntime(676): FATAL EXCEPTION: main
08-03 00:45:25.287: E/AndroidRuntime(676): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.arsenic.test01/com.arsenic.test01.ContactActivity}: java.lang.NullPointerException
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread.access$600(ActivityThread.java:127)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.os.Looper.loop(Looper.java:137)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread.main(ActivityThread.java:4448)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.lang.reflect.Method.invokeNative(Native Method)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.lang.reflect.Method.invoke(Method.java:511)
08-03 00:45:25.287: E/AndroidRuntime(676):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
08-03 00:45:25.287: E/AndroidRuntime(676):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
08-03 00:45:25.287: E/AndroidRuntime(676):  at dalvik.system.NativeStart.main(Native Method)
08-03 00:45:25.287: E/AndroidRuntime(676): Caused by: java.lang.NullPointerException
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.lang.String$CaseInsensitiveComparator.compare(String.java:89)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.lang.String$CaseInsensitiveComparator.compare(String.java:71)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.util.TimSort.binarySort(TimSort.java:261)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.util.TimSort.sort(TimSort.java:204)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.util.TimSort.sort(TimSort.java:169)
08-03 00:45:25.287: E/AndroidRuntime(676):  at java.util.Arrays.sort(Arrays.java:2038)
08-03 00:45:25.287: E/AndroidRuntime(676):  at com.arsenic.test01.ContactActivity.onCreate(ContactActivity.java:45)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.Activity.performCreate(Activity.java:4465)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-03 00:45:25.287: E/AndroidRuntime(676):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
08-03 00:45:25.287: E/AndroidRuntime(676):  ... 11 more
08-03 00:45:26.718: I/Process(676): Sending signal. PID: 676 SIG: 9

```