2011-06-06 88 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> 


希望這有助於