简体   繁体   中英

Can't run GWT ServiceAsync

I am trying to create a asyncallback to return a list with all the customers from a GAE JDO database in app-engine. I have done a login class that works well but only returns a string. Now I am trying to get a List but I have the errors that come from:

18:05:39.219 [ERROR] [prototipov8]    subtype   
com.google.gwt.resources.client.impl.ExternalTextResourcePrototype.ETRCallback is not default 
instantiable (it must have a zero-argument constructor or no constructors at all) and has no 
custom serializer. (reached via
com.google.gwt.user.client.rpc.AsyncCallback<java.util.List<pt.sites.shared.model.Customer>>)

and

[ERROR] [prototipov8] - subtype com.google.gwt.user.client.rpc.AsyncCallback<T> 
is not instantiable

Full error:

17:54:07.268 [ERROR] [prototipov8] Unable to load module entry point class pt.info2000.sites.client.old.Main (see associated exception for details)
 java.lang.RuntimeException: Deferred binding failed for 'pt.info2000.sites.client.old.TableService' (did you forget to inherit a required module?)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:53)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at pt.info2000.sites.client.old.Main.<clinit>(Main.java:30)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:654)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:363)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.core.ext.UnableToCompleteException: (see previous log entries)
at com.google.gwt.dev.shell.ModuleSpace.rebind(ModuleSpace.java:595)
at com.google.gwt.dev.shell.ModuleSpace.rebindAndCreate(ModuleSpace.java:455)
at com.google.gwt.dev.shell.GWTBridgeImpl.create(GWTBridgeImpl.java:49)
at com.google.gwt.core.client.GWT.create(GWT.java:97)
at pt.info2000.sites.client.old.Main.<clinit>(Main.java:30)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.google.gwt.dev.shell.ModuleSpace.loadClassFromSourceName(ModuleSpace.java:654)
at com.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:363)
at com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:525)
at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:363)
at java.lang.Thread.run(Unknown Source)

The call

        public static final TableServiceAsync table = GWT.create(TableService.class);

TableService

@RemoteServiceRelativePath("getObjects")
 public interface TableService extends RemoteService {

List<Customer> getObjects(AsyncCallback<List<Customer>> callback);

  }

TableServiceAsync

  public interface TableServiceAsync {

    void getObjects(AsyncCallback<List<Customer>> callback, 
             AsyncCallback<List<Customer>> asyncCallback);

  }

Costumer.class a JDO in gae

 @PersistenceCapable

public class Customer extends User implements Serializable {

/**
 * 
 */
private static final long serialVersionUID = 1L;

@Persistent
private Date birthDate;

@Persistent
private int nib;

@Persistent
public Set<Key> companies;

@Persistent
public Set<Key> sugestions;

@Persistent
public Set<Key> documents;

/**
 * @param code
 * @param name
 * @param description
 * @param creationDate
 * @param modificationDate
 * @param creator
 * @param lastModifier
 * @param username
 * @param password
 * @param avatar
 * @param activo
 * @param cookie
 * @param loginIP
 * @param roles
 * @param contacts
 */
public Customer(int code, String name, String description,
        Date creationDate, Date modificationDate, Key creator,
        Key lastModifier, String username, String password, Blob avatar,
        boolean activo, String cookie, String loginIP, Set<Key> roles,
        Set<Key> contacts) {
    super(code, name, description, creationDate, modificationDate, creator,
            lastModifier, username, password, avatar, activo, cookie, loginIP,
            roles, contacts);
}

public Customer() {

}

I have already try to find a solution but I couldn't make it work, has anyone meet this error? Any suggestions or solutions? Thank you in advance for the time taken to read this. Any code that can help please ask.

Edit1: I have a default constructor with no parameters and the class implements serializable, and I can serialize it. This code works in the Customer class;

Serializable c = new Customer(); 

Edit2: Added requested code and the full error. Tried to pass the list to hashset but the error still persists. Didn't find any other solution.

In order for an object to be Serializable , it needs to have a default constructor with no parameters. That's what this error is saying. You can only pass objects from client side to server side (and vice versa) if the object is Serializable.

Your interfaces are wrong. You should read the GWT documentation for making RPC calls.

Your TableService interface should look like this, assuming you don't need any parameters for the method.

@RemoteServiceRelativePath("getObjects")
public interface TableService extends RemoteService {
    List<Customer> getObjects();
}

Your TableServiceAsync will then look like this

public interface TableServiceAsync {
    void getObjects(AsyncCallback <List<Customer>> callback);
}

AsyncCallback is not Serializable, which is why you had this error. If you needed to pass a parameter to your method, for example an array of Strings to identify which customers to get, your interfaces would look like this

@RemoteServiceRelativePath("getObjects")
public interface TableService extends RemoteService {
    List<Customer> getObjects(String[] ids);
}

public interface TableServiceAsync {
    void getObjects(String[] ids, AsyncCallback <List<Customer>> callback);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM