0

Value Proxy の取得中にヌル ポインター例外が発生します。コードは次のとおりです。

@PersistenceCapable
public class Student {

    //**********Compulsory
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    Long id;

    Integer version;

    String name;
    List<String> hobbies;
    Address address;

    public Student(){
        version = 1;
    }

    public Long getId(){
        return id;
    }

    public Integer getVersion(){
        return version;
    }

    public static Student findStudent(Long id){
        return new Student();
    }

    public static Student findStudentAddress(){
        Student s = new Student();
        s.setAddress(new Address("city", "state"));
        return s;
    }
}


@PersistenceCapable
public class Address implements Serializable{
    @Persistent(defaultFetchGroup = "true")
    String city,state;

    public Address(){}

    public Address(String city,String state){
        this.city = city;
        this.state = state;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }
}

@ProxyFor(Student.class)
@ExtraTypes({AddressProxy.class})
public interface StudentProxy extends EntityProxy {
    //****Compulsory
    public Long getId();
    public Integer getVersion();
    //**************

    //Custom here onwards
    public String getName();

    public void setName(String name);

    public List<String> getHobbies();

    public void setHobbies(List<String> hobbies);

    public AddressProxy getAddress();

    public void setAddress(AddressProxy address);

    public void setId(Long id);

    public void setVersion(Integer version);
}

@Service(Student.class)
public interface StudentRequest extends RequestContext {
    //********Invoked without custom object - statically**** usually used to pull data from server
    Request<StudentProxy> findStudent(Long id);
    Request<StudentProxy> findStudentAddress();
}

@ProxyFor(Address.class)
public interface AddressProxy extends ValueProxy {
    public String getCity();
    public void setCity(String city);
    public String getState();
    public void setState(String state);
}

public class Home implements EntryPoint {
    MyRequestFactory rf;
    StudentRequest sr;
    @Override
    public void onModuleLoad() {

        GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
            public void onUncaughtException(Throwable e) {
                e.printStackTrace();                
            }
        });

        rf = GWT.create(MyRequestFactory.class);
        rf.initialize(new SimpleEventBus());

        sr = rf.studentRequest();
        sr.findStudentAddress().fire(new Receiver<StudentProxy>() {
            public void onSuccess(StudentProxy response) {
                System.out.println(response.getAddress().getCity());
            }
        });
    }
}

com.google.web.bindery.event.shared.UmbrellaException: Exception caught: null
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:414)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$5.onTransportSuccess(AbstractRequestContext.java:1151)
    at com.google.web.bindery.requestfactory.gwt.client.DefaultRequestTransport$1.onResponseReceived(DefaultRequestTransport.java:136)
    at com.google.gwt.http.client.Request.fireOnResponseReceived(Request.java:258)
    at com.google.gwt.http.client.RequestBuilder$1.onReadyStateChange(RequestBuilder.java:412)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessagesWhileWaitingForReturn(BrowserChannelServer.java:338)
    at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:219)
    at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:571)
    at com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:279)
    at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:91)
    at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
    at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:242)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
    at com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
    at com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:172)
    at com.google.gwt.dev.shell.BrowserChannelServer.reactToMessages(BrowserChannelServer.java:293)
    at com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:547)
    at com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
    at com.gwtrf.client.Home$2.onSuccess(Home.java:28)
    at com.gwtrf.client.Home$2.onSuccess(Home.java:1)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.onSuccess(AbstractRequest.java:129)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext$StandardPayloadDialect.processPayload(AbstractRequestContext.java:381)
    ... 30 more

サーバー側で初期化されたクライアント側の値プロキシを取得するのを手伝ってください。

4

1 に答える 1

0

メソッドを使用して取得する関係を指定する必要がありますwith()

あなたの場合、これを追加するとコードが機能するはずです:

sr.findStudentAddress().with("address").fire(...);
于 2013-06-14T06:33:21.320 に答える