Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
ganeshS
Posts: 133
Registered: ‎12-31-2009
My Device: Not Specified

Contact saving problem

Hello Friends,

 

 

I am trying to download contacts from server and then save these contacts in phonebook with the following code. Following code is for saving the contacts into phonebook. This code works perfect if I am saving 2 or three contacts. But when I try to download 10 or more contacts, I am getting error. The downloading of more than 10 contacts is working but it is not saving the contacts and giving following error. If I comment the following code in my application, then it works fine. (I mean downloading is done but contacts are not saved)

 

 

The error is "Uncaught exception Application net_rim_bb_phone_app(66) is not responding ; process terminated"

 

 

If I use follwoing code in Timer

then I am getting following error

" Uncaught exception Application net_rim_bb_phone_app(206) is not responding ; process terminated"

 

What could be the problem??

 

 

 

 

public void saveContacts()
{


if(timer!=null)
{
timer.cancel();
timer=null;
}


	String conStr = new String(ContactRetrieve);


	try
	{

	BlackBerryContactList contactList = null;

	contactList = (BlackBerryContactList) PIM.getInstance()
			.openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);


	while (conStr.length() != 0) {
		 {

			String lName="MyName",
			fName="MyLastName",
			tel ="1212989898",
			email="myid@mymail.com",
			mobile="98989898";


			try {

				String[] arrayField = new String[5];


				arrayField[BlackBerryContact.NAME_FAMILY] = lName;// LastName
				arrayField[BlackBerryContact.NAME_GIVEN] = fName;// FirstName
				arrayField[BlackBerryContact.NAME_PREFIX] = "";// Title



				if (contactList
						.isSupportedField(BlackBerryContact.NAME)) {
					contact.addStringArray(BlackBerryContact.NAME,
							PIMItem.ATTR_NONE, arrayField);// see above

				}

				if (contactList
						.isSupportedField(BlackBerryContact.EMAIL)) {
					contact.addString(BlackBerryContact.EMAIL,
							BlackBerryContact.ATTR_NONE, email);
				}

				if (contactList.isSupportedAttribute(
						BlackBerryContact.TEL,
						BlackBerryContact.ATTR_HOME)) {
					contact.addString(BlackBerryContact.TEL,
							BlackBerryContact.ATTR_WORK, tel);
				}

				if ((contactList).isSupportedAttribute(
						BlackBerryContact.TEL,
						BlackBerryContact.ATTR_MOBILE)) {
					contact.addString(BlackBerryContact.TEL,
							BlackBerryContact.ATTR_MOBILE, mobile);
				}
				

				contact.commit();
				Thread.currentThread().sleep(600);
				Thread.yield();
			} catch (Exception e) {

				e.printStackTrace();
		}
		}
	}

}
	catch(Exception e)
	{

	}
	Dialog.inform("Download Successful..");

}

 

Thank you

 

 

 

 

 

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Contact saving problem

i would guess you do this in a phonelistener. code in a phonelistener is executed in the context of the phone application.

you are also using thread.sleep without having a dedicated thread, this means you block the whole phone application for this time.

 

1. move processing to your app, using global events, runtimestore or callbacks+invokelater.

2. use a dedicated thread

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
ganeshS
Posts: 133
Registered: ‎12-31-2009
My Device: Not Specified

Re: Contact saving problem

Hello Simon_hain,

 

Thank you for your reply,

 

I implemented dedicated thraed as per your suggestion. But then also I am getting same type of problem. :smileyindifferent:

 

I am not able to get what the problem is??

 

Thank you

Please use plain text.
Developer
simon_hain
Posts: 15,869
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Contact saving problem

move the processing into your own application as described in

http://supportforums.blackberry.com/t5/Java-Development/How-To-use-a-phone-listener/td-p/482107

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.