Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inserting contacts

 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Roland Mueller
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Log.i(...) in line 5 should be a typo and not compile.

For getting some help about the NullPointerException you should have a look at the stacktrace: this will tell where in your code the NPE occured.

-Roland
 
Roland Mueller
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java != Android. thus the Log.i() is pretty valid. Sorry for the confusion about the Log.i() call!

However, the sentence about the stacktrace is OK.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does that mean "getContentResolver()" returns null? Do that method's javadocs talk about the circumstances under which it can return null?
 
Roland Mueller
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
Roland Mueller
Greenhorn
Posts: 7
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
.... forgot to mention where I found the deciding hint:
http://stackoverflow.com/questions/8414192/how-to-create-a-contact-programmatically
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are a great programmer, Roland! Thanks a lot. I learned something from this.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

content://com.android.contacts/phone_lookup

What does it mean? I might show you the code too, but I'm not sure it is necessary.

Thanks for help!
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
However, I decided to post the code for the method I use to list the contacts. Perhaps this way I'll get more chances to receive an explanation.

 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Monica Marcus
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for my English ... "it leaves me working on ..."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic