Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Inserting contacts

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 149
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 149
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 43075
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 149
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 149
1
Android Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for my English ... "it leaves me working on ..."
 
Brace yourself while corporate america tries to sell us its things. Some day they will chill and use tiny ads.
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic