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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Highlighted
Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Invalid Argument Exception?

I am getting an invalid argument exception on the following code. The code is meant to add a contact to the user's blackberry. Why am I getting this exception?

 

 

try {
ContactList cl = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_WRITE);
Contact c = cl.createContact();
c.addString(Contact.NAME_GIVEN, PIMItem.ATTR_NONE, "The Red Herring");
c.addString(Contact.EMAIL, PIMItem.ATTR_NONE, "red@herring.com");
c.addString(Contact.NICKNAME, PIMItem.ATTR_NONE, "RH");
c.addString(Contact.ADDR_STREET, PIMItem.ATTR_NONE, "Right Behind You");
c.commit();
cl.close();
} catch (PIMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

 

 

From,
Noah NU
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Invalid Argument Exception?

I would suggest adding a breakpoint above the addString()s and see which one is doing it (if they are, that is). According to the API you'll get an IllegalArgumentException if you are adding the wrong type to a field. Another thing to watch for is a field that can have mutliple entries...fought with that myself before.

Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invalid Argument Exception?

I am getting the exception for each addString() and I even followed the guidelines in the documentation for which data types are acceptable for each field, string, string array, int, etc..

From,
Noah NU
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Invalid Argument Exception?

NAME is a string array.

 

See this example in the docs:

 

 ContactList contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.WRITE_ONLY);
if (contactList.isSupportedField(Contact.NAME)) {
     Contact contact = contactList.createContact();
     String[] name = new String[ contactList.stringArraySize( Contact.NAME ) ];
     name[Contact.NAME_GIVEN] = "Kate";
     name[Contact.NAME_FAMILY] = "Turner";
     contact.addStringArray(Contact.NAME, Contact.ATTR_NONE, new String[] {"Kate Turner"});
     contact.commit();
     return true;
}  else {
     return false;
}

Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invalid Argument Exception?

[ Edited ]

Yes I am aware of that. In my code above I used NAME_GIVEN not name. Also the error occurs on EVERY addString not just the name one. What could be the problem?

 

EDIT: I just looked over your example again and I am a bit confused. You declare and set a String array yet you never use it.

 

Here you set it:

 

 

String[] name = new String[ contactList.stringArraySize( Contact.NAME ) ];
name[Contact.NAME_GIVEN] = "Kate";
name[Contact.NAME_FAMILY] = "Turner";

 

 

Yet here, the place were you add the array, you dont mention your string array name anywhere, you create a new array on the spot.

 

 

contact.addStringArray(Contact.NAME, Contact.ATTR_NONE, new String[] {"Kate Turner"});

 

 

From,
Noah NU
Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: Invalid Argument Exception?

My guess is he probably wrote this to help you out but didn't actually try to compile it. His string array that he made but didn't use is what he most likely meant to pass as an argument. Please remember that we are here to guide you in the right direction, not do your work for you.
Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Invalid Argument Exception?

Sorry, I copied that from the javadoc example.

 

However, if you look closely you will find that the name argument that is passed is in fact an array.

 

Developer
Posts: 138
Registered: ‎01-09-2011
My Device: Blackberry Tablet OS

Re: Invalid Argument Exception?

[ Edited ]

Yes I am aware of that however even when I removed the Name fields I still received the error. I tried using addString on the Address field, the Email field and the Name fields - all together as well as seperately.

 

@

From,
Noah NU