当我使用此代码时,它会给出错误

时间:2011-06-06 10:07:14

标签: gwt-rpc

  

可能重复:
  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("abc@in.gappsdemo.in", "xyz@123");
    } 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("demo@in.gappsdemo.in");
    primaryMail.setRel("http://schemas.google.com/g/2005#home");
    primaryMail.setPrimary(true);
    contact.addEmailAddress(primaryMail);

    Email secondaryMail = new Email();
    secondaryMail.setAddress("demo@in.gappsdemo.in");
    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/demo@in.gappsdemo.in/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 个答案:

答案 0 :(得分:0)

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

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

1.在'com.hellomvp'(com.hellomvp.events)中创建新包'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>


希望这会有所帮助。