Exception while dispatching incoming RPC call

825 views
Skip to first unread message

KuoYing@Taiwan

unread,
Oct 1, 2010, 9:08:29 PM10/1/10
to Google Web Toolkit
Hi:
I using GWT but it get a error(I want to GWT with JPA) :
[WARN] Exception while dispatching incoming RPC call
com.google.gwt.user.server.rpc.UnexpectedException: Service method
'public abstract void
org.kuoying.client.GreetingService.save(org.kuoying.client.RpcItem)'
threw an unexpected exception: java.lang.NullPointerException
at
com.google.gwt.user.server.rpc.RPC.encodeResponseForFailure(RPC.java:
378)
......................

souce code:

public class First implements EntryPoint {
/**
* This is the entry point method.
*/
public void onModuleLoad() {
Button sendButton = new Button("Send");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
sendButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
GreetingServiceAsync greetingService = GWT
.create(GreetingService.class);

String textToServer = nameField.getText();
RpcItem ri = new RpcItem();
ri.setId(7);
ri.setUsername(textToServer);
greetingService.save(ri, new AsyncCallback() {
public void onFailure(Throwable caught) {
Window.alert("Fail");
}
public void onSuccess(Object result) {
Window.alert("Success");
}
});
}
});
}
}
------------------------------------------
@RemoteServiceRelativePath("greet")
public interface GreetingService extends RemoteService {
// String greetServer(String name) throws IllegalArgumentException;
void save(RpcItem ri);
}
----------------------------------------------
public interface GreetingServiceAsync {
void save(RpcItem ri, AsyncCallback callback);
}
--------------------------------------------
public class GreetingServiceImpl extends RemoteServiceServlet
implements
GreetingService {

private static final long serialVersionUID = 1L;

@Override
public void save(RpcItem ri) {
EntityManagerFactory emf;
EntityManager em = null;
try {
emf = Persistence.createEntityManagerFactory("oo");
em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(ri);
em.getTransaction().commit();
} finally {
em.close();
}
}
}



What can I do?? THX^^

KuoYing@Taiwan

unread,
Oct 1, 2010, 9:06:38 PM10/1/10
to Google Web Toolkit

Greg Dougherty

unread,
Oct 4, 2010, 4:55:05 PM10/4/10
to Google Web Toolkit
EntityManagerFactory emf;
EntityManager em = null;
try {
emf =
Persistence.createEntityManagerFactory("oo");
em = emf.createEntityManager();
em.getTransaction().begin();
em.persist(ri);
em.getTransaction().commit();
} finally {
em.close();
}

If you throw an exception in Persistence.createEntityManagerFactory
(), em will be null when you try to call close on it. Put an
if (em != null)
test in your finally.
Reply all
Reply to author
Forward
0 new messages