Android Forums

Go Back   These FORUMS ARE DISABLED!! OUR NEW FORUMS ARE AT http://androidforum.com/ > Android Coders > Android Development, Answers, Tutorials, and Code Snippets
Connect with Facebook

Click Here To Register!
 
 
LinkBack Thread Tools Display Modes
Old 08-26-2010, 12:39 AM   #1
New Member
 
Join Date: Aug 2010
Posts: 1
Friends: 0
View adhavan's Profile   View adhavan's Photo Album   View adhavan's Blog   View Social Groups
hi,
i want to add a contact to my application. i tried this coding but it is throwing NULL POINTER EXCEPTION i don't where i am going wrong
Code:
ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
		ops.add(ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
				.withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE)
				.withValue(ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME, name)
		        .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE)
		        .withValue(ContactsContract.CommonDataKinds.Phone.NUMBER, phone)
		        .withValue(ContactsContract.CommonDataKinds.Phone.TYPE, phoneType)
		        .withValue(ContactsContract.Data.MIMETYPE,ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE)
		        .withValue(ContactsContract.CommonDataKinds.Email.DATA, email)
		        .withValue(ContactsContract.CommonDataKinds.Email.TYPE, emailType)		        
		   .build());
		try { 
			
		    getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops); 
		    Context ctx = getApplicationContext();
		    CharSequence txt = "Contact " + name +" added successfully";
			 int duration = Toast.LENGTH_LONG;
			 Toast toast = Toast.makeText(ctx, txt, duration);
			 toast.show();
		} catch (Exception e) {
			
			
			
		}
adhavan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in Technorati
 

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding contacts to text message problem. lcammann Nexus One 0 07-02-2010 10:37 AM
Need help adding music to my new phone sbuff28 T-Mobile, Vodafone, Sprint, Verizon, Rogers, AT&T etc. 1 06-08-2010 12:11 PM
Adding calendar johngies Motorola 1 12-24-2009 01:12 PM
Adding a contact nb2a Droid 0 12-16-2009 10:56 AM
Problem with adding SDK components BenDC Android Development, Answers, Tutorials, and Code Snippets 0 11-09-2009 07:23 PM


Unlocked G1 Phones | Buy T-Mobile G1 | Google Phone

All times are GMT -6. The time now is 06:30 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.
Copyright (c) 2012 TalkAndroid.com. All rights reserved.