I am trying to insert contacts using the following method (in my activity class):
but I get the RunTimeException: aggregate contacts are created automatically. This happens in the last line of the method. If I use instead the commented one, I get NullPointerException. I don't really understand what's happening. How to get rid of the errors? I would very much appreciate your help.
Thank you, Roland, for the advice. As I mentioned in my post, the NullPointerException occurs in the last line of the method. I tried to see which could be the null pointer, but I saw that none of the objects that appear in this line point to null. Maybe I miss something, but here's the stack trace. I cannot get any more information from the stack trace:
Perhaps you or someone else can help me to find out why I get the NullPointerException. Thank you in advance!
Oh, I'm sorry. I must say that I get the NullPointerException when the last line is replaced by the commented-out line. That is, I get NullPointerException from the line
The problem should be in the data provided when using the URL from android.provider.ContactsContract.Data. With a more simple example I got an NPE unless Data.RAW_CONTACT_ID was inserted into the cv.
In your case you could use the i from the loop to add cv.put(Data.RAW_CONTACT_ID, i); to every c/o item.
Now, after I added three contacts to my list of contacts, I wanted to show (list) them using a cursor and a ListAdapter. I don't get any error but instead of the list of contacts I see written on the screen only the following URI:
I discovered which is the line that writes that output on the screen phone: it is the one starting with txt.setText(...
Ok, so this in fact answers my question and lefts me working on the program to get the list of contacts.... hopefully.