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
Developer
safycool
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified
Accepted Solution

Problem with PIM.

Hi,

 

 I am trying to import vCard to contacts. But I am facing problem.

 

Here is the snippet.....

 

 

     byte[] ch = inputStreamToBytes(is);      
     
       
       String ss = new String(ch);
       System.out.print("The file read is :"+ss); 

       ByteArrayInputStream bais = new ByteArrayInputStream(ch);         
       
        PIMItem[] items1 = BlackBerryPIM.getInstance().fromSerialFormat(bais, "UTF-8");
        BlackBerryContact c = (BlackBerryContact) (items1[0]);
        BlackBerryContactList cl = (BlackBerryContactList) BlackBerryPIM.getInstance().openPIMList (BlackBerryPIM.CONTACT_LIST, BlackBerryPIM.READ_WRITE);
        cl.importContact(c);
        c.commit();

 

 

 

I get the following print on the console.

 

 

The file read is :BEGIN:VCARD

VERSION:2.1

N;CHARSET=utf-8:Madhia;Sarfaraz

ORG;CHARSET=utf-8:Abcd

TITLE;CHARSET=utf-8:smileyfrustrated:SE

TEL;TYPE=WORK,VOICE:6464646

TEL;TYPE=WORK,VOICE:464646

TEL;TYPE=HOME,VOICE:46464646

TEL;TYPE=HOME,VOICE:464646

TEL;TYPE=VOICE,CELL:4646646

TEL;TYPE=VOICE,PAGER:464646

TEL;TYPE=FAX:4646464646

TEL;TYPE=VOICE:6464646

EMAIL;TYPE=INTERNET:ffsfsf

X-RIM-PIN:64646466

END:VCARD

Exception in saveContacts:javax.microedition.pim.PIMException: Contact does not belong to a ContactList.

 

I tried using PIM, Contact instead of BlackberryPIM and BlackberryContact but got the same Exception. Please let me know where am I wrong

 

Thnks and awaiting your response

Developer
BBDeveloper
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem with PIM.

Not sure and not tried. Give a try like String ss = new String(ch,"UTF-8") instead of String ss = new String(ch).

Use Search. "Accept Solution" If the problem is resolved.
Developer
safycool
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem with PIM.

I alse checked the sop after 

 

PIMItem[] items1 = BlackBerryPIM.getInstance().fromSerialFormat(bais, "UTF-8":smileywink:;

 

System.out.println("items1...."+items1.length+"  items1[0]..."+items1[0].countValues(Contact.TEL)+"  items1[0]>>>>"+items1[0].countValues(Contact.EMAIL));

 

 

It properly returns the number of attribute in TEL and Email as 8 and 1 respectively.

 

Even the cl.importContact(c); does not throw an exception

 

c.commit()  throws javax.microedition.pim.PIMException: Contact does not belong to a ContactList.

 

Can i know what is the reason.

 

The problem is not with the string the file is properly converted to string...I printed the String for reference of contact which is there on the vCard.

 

 

Thnks...

 

Developer
safycool
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem with PIM.

I furthur debugged the code and the snippet is given below. This is only the lower half the code the upper half is given in the initial post

 

cl.importContact(contact);
        if (cl.isSupportedField(Contact.NAME)){
            String []name = contact.getStringArray(Contact.NAME, 0);
            String givenName=(name[contact.NAME_GIVEN]);
            String familyName = (name[Contact.NAME_FAMILY]);
            System.out.println("givenName:"+ givenName+"  familyName:"+familyName);
            }
            if (cl.isSupportedField(Contact.TEL)){
            String phoneNum = contact.getString(Contact.TEL, 0);
            System.out.println("phoneNum:"+phoneNum);
           
            }
            if (cl.isSupportedField(Contact.ORG)){
            String org = contact.getString(Contact.ORG, 0);
            System.out.println("org:"+org);
            }
        System.out.println("contacts imported......");
       
       
        contact.commit();
        System.out.println("contacts committed......");

 

 

 

The above code gives the following sop

 

givenName:smileyfrustrated:arfaraz  familyName:Madhia
phoneNum:6464646
org:Abcd

contacts imported......
Exception in saveContacts:javax.microedition.pim.PIMException: Contact does not belong to a ContactList.

 

The sop are as per the details in the vCard.

 

I really cant understand why contact.commit() is  throwing javax.microedition.pim.PIMException: Contact does not belong to a ContactList.

 

 I am testing on Blackberry Eclipse plugin 4.5.0

 

Thnks...

 

 

 

 

Developer
safycool
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem with PIM.

Anyone has any clue...How to tackle this problem.

 

 

Thanks....

BlackBerry Development Advisor
MSohm
Posts: 14,757
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Problem with PIM.

You should call commit on the Contact object returned from the importContact object, not the Contact object you are using as a parameter.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Developer
safycool
Posts: 198
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem with PIM.

Thnks it worked for me.....
Contributor
retola
Posts: 23
Registered: ‎03-10-2010
My Device: 8530

Re: Problem with PIM.

Hello,I have a problem with PIM ,with  simulators all go right!!!!!!!My application read contacts and return the telephone number of all contacts,but with the smartphone I have always this exception

 

 

javax.microedition.pim.PIMException

 

I have setting all allow for the application  on my blackberry .

 

 

could help me?

 

 

 
 private static Enumeration getContacts()

{
           
        try {
          
          contactlist = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST, PIM.READ_ONLY);  
          if (contactlist.isSupportedField(Contact.TEL)) {   enumContact =contactlist.items(); }
          
        }catch(PIMException e){}
       
           return enumContact;
          
          
 }

 

I think it's this code to get exception.

Contributor
retola
Posts: 23
Registered: ‎03-10-2010
My Device: 8530

Re: Problem with PIM.

The message on my blackberry is:

 


the application has tried to modify the data customer to concur?

 

then push yes


Uncaught exception javax.microedition.pim.ReadWrite!!!!!!

 

 

 

help!!!!!!!!!

Contributor
retola
Posts: 23
Registered: ‎03-10-2010
My Device: 8530

Re: Problem with PIM.

The problem is closed with the code:

 

 

 

public static Enumeration getContacts()

{
           
     String[] lists = PIM.getInstance().listPIMLists(PIM.CONTACT_LIST);
     ContactList contactList;
     Enumeration items=null;
     Vector risultato=new  Vector();
     String telefono="";
     
      for (int i = 0; i<lists.length;i++)
    {
     try{
       contactList = (ContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.getInstance().READ_WRITE, lists[i]);  items = contactList.items();
    }catch(PIMException e ){}  }
   
          
     return items;
 
 
}

 

but when I run the application I have to wait several minutes.....how can I improve my application?

 

 

Thanks!!!!!!