2011-06-06 48 views
0
public ContactEntry createContact(String username)throws IllegalArgumentException { 
     // Create the entry to insert 
     ContactsService myService = new ContactsService("exampleCo-exampleApp-1"); 
     try { 
      myService.setUserCredentials("[email protected]", "[email protected]"); 
     } catch (AuthenticationException e1) { 
      // TODO Auto-generated catch block 
      e1.printStackTrace(); 
     } 
     String name = "neha'sContact"; 
     String notes = "this is some notes from gdata API client"; 

     ContactEntry contact = new ContactEntry(); 
     contact.setTitle(new PlainTextConstruct(name)); 
     contact.setContent(new PlainTextConstruct(notes)); 

     Email primaryMail = new Email(); 
     primaryMail.setAddress("[email protected]"); 
     primaryMail.setRel("http://schemas.google.com/g/2005#home"); 
     primaryMail.setPrimary(true); 
     contact.addEmailAddress(primaryMail); 

     Email secondaryMail = new Email(); 
     secondaryMail.setAddress("[email protected]"); 
     secondaryMail.setRel("http://schemas.google.com/g/2005#work"); 
     secondaryMail.setPrimary(false); 
     contact.addEmailAddress(secondaryMail); 

     ExtendedProperty favouriteFlower = new ExtendedProperty(); 
     favouriteFlower.setName("favourite flower"); 
     favouriteFlower.setValue("daisy"); 
     contact.addExtendedProperty(favouriteFlower); 

     ExtendedProperty sportsProperty = new ExtendedProperty(); 
     sportsProperty.setName("sports"); 
     XmlBlob sportKinds = new XmlBlob(); 
     sportKinds.setBlob(new String("<dance><salsa/><ballroom dancing/><dance/>")); 
     sportsProperty.setXmlBlob(sportKinds); 
     contact.addExtendedProperty(sportsProperty); 
     System.out.println(contact); 

     // Ask the service to insert the new entry 
     try{ 
      System.out.println("Inside try Block:"); 
      URL postUrl = new URL("https://www.google.com/m8/feeds/contacts/[email protected]/full"); 
      System.out.println("Inside try Block1:"); 
      return myService.insert(postUrl, contact); 



     } 
     catch (Exception e) { 
      // TODO: handle exception 
      e.printStackTrace(); 
     } 
     return contact; 
    } 

当我使用此代码它提供了以下错误: [错误] [simplerpc] - 第9行:没有源代码可用的类型com.google.gdata .data.contacts.ContactEntry;你忘了继承一个必需的模块吗?当我使用此代码它给出错误

回答

0

您不能直接在GWT中使用服务器端代码。 由于GWT将无法为com.google.gdata.data.contacts.ContactEntry生成JavaScript,因此会出现上述错误。

+0

此代码在服务器端,然后它也给出错误 – Neha 2011-06-06 07:51:30

+0

@Neha你是否直接返回ContactEntry对象到客户端(GWT)端? – jaxb 2011-06-06 09:50:55

+0

是的,我正在返回ContactEntry对象 – Neha 2011-06-06 10:15:13

相关问题