SIM Android Contacts

124 views Asked by At

This is a code i found on other StackOverflow questions, it works well (as they say) for that users asking a question to fetch only the SIM Contacts from and Android phone.

However, when i try to build it, Android Studio get a NullPointerException at line "ClsSimphoneNo.replaceAll("\D","");".

I really dunno why, do you have any suggestions?

public void allSIMContact(View view)
{
    try {

String ClsPhonename = null;
String ClsphoneNo = null;  
Uri simUri = Uri.parse("content://icc/adn"); 
Cursor cursorSim = this.getContentResolver().query(simUri,null,null,null,null);

while (cursorSim.moveToNext()) 
{      
    ClsSimPhonename =cursorSim.getString(cursorSim.getColumnIndex("name"));
    ClsSimphoneNo = cursorSim.getString(cursorSim.getColumnIndex("number"));
    ClsSimphoneNo.replaceAll("\\D","");
    ClsSimphoneNo.replaceAll("&", "");
    ClsSimPhonename=ClsSimPhonename.replace("|","");
        System.out.println("SimContacts"+ClsSimPhonename);
        System.out.println("SimContactsNo"+ClsSimphoneNo);       
}
catch(Exception e)
{
     e.printStackTrace();
}
0

There are 0 answers