0

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();
}
  • add the log lines before you use phone no and name. – siva Jun 21 '15 at 17:16
  • i knew that the log line would normally be put on the catch expection... where do you suggest me to put that? Into the while statement or right out of it, after the declaration of cursorSim? Or any other place, tell me – Luca Vitrini Jun 24 '15 at 08:48
  • Before the call to replaceAll, you can keep your logs as well as you can check for null data. – siva Jun 24 '15 at 08:51

0 Answers0