2011-06-06 92 views
0

可能重复:
when i am using this code it gives error当我使用此代码提示错误

public class SharedContactServiceImpl extends RemoteServiceServlet implements 
SharedContactService { 
/** 
* 
*/ 
private static final long serialVersionUID = 1L; 

public ContactEntry createContact()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 = "nehaContact"; 
    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; 
} 

}

我使用服务器端的代码提示错误:

[ERROR] [simplerpc] - Line 9: No source code is available for type com.google.gdata.data.contacts.ContactEntry; did you forget to inherit a required module? 
+1

优秀称号! – davin 2011-06-06 10:26:57

回答

0

发生此错误的原因是您在客户端代码中使用了com.google.gdata.data.contacts.ContactEntry(将其从您的服务中返回到客户端代码) GWT将客户端对象编译为Javascript。要修复它,你需要告诉GWT在哪里找到所有转换为Javascript的对象的源代码(所有客户端的东西)。

为此,您需要在“YourProject.gwt.xml”中添加诸如<source path='events'/>之类的内容。下面是一个例子:在 'com.hellomvp'(Using helloMVP

1.创建新包 '事件'(com.hellomvp.events)
2.增加<source path='events'/>为“HelloMVP.gwt.xml 现在它看起来像这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<module rename-to="helloMVP"> 
    <inherits name='com.google.gwt.user.User'/> 

    <inherits name='com.google.gwt.user.theme.standard.Standard'/> 
    <inherits name="com.google.gwt.activity.Activity"/> 
    <inherits name="com.google.gwt.place.Place"/> 

    <entry-point class='com.hellomvp.client.HelloMVP'/> 

    <replace-with class="com.hellomvp.client.ClientFactoryImpl"> 
    <when-type-is class="com.hellomvp.client.ClientFactory"/> 
    </replace-with> 

    <!-- Specify the paths for translatable code     --> 
    <source path='client'/> 
    <source path='shared'/> 
    <source path='events'/> 

</module> 


希望这有助于