java - AbstractRequestContext.doFire 处的 NullPointerException(AbstractRequestContext.java :1102)

标签 java google-app-engine gwt

我刚刚开始使用 Google AppEngine 进行开发,现在遇到了第一个问题。

我选择Todo-Example-Project来自 Google-IO 2011 并进行一些更改,现在我在我的应用程序中得到以下 StackTrace:

Caused by: java.lang.NullPointerException: null
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.doFire(AbstractRequestContext.java:1102)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequestContext.fire(AbstractRequestContext.java:569)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.fire(AbstractRequest.java:54)
    at com.google.web.bindery.requestfactory.shared.impl.AbstractRequest.fire(AbstractRequest.java:59)

我尝试使用以下代码在 GWT-Client 中创建一个新实体:

MyRequest request = requestFactory.myRequest();
request.createTime().fire();

服务类中的代码

static DataStore db = new DataStore();

public static Time createTime() {
    return db.update(new Time());
}

这是数据存储类中的代码

public Time update(Time item) {
    PersistenceManager pm = PMF.get().getPersistenceManager();
    try {
        pm.makePersistent(item);
        return item;
    } finally {
        pm.close();
    }
}

我希望你能帮助我解决这个问题。

谢谢

编辑: 我想我应该补充一点,我当然已经实现了 TimeLocator-Class 和 ServiceLocator-Class。

这是我的 web.xml,因为我认为可能存在问题:

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemalocation="http://java.sun.com/xml/ns/javaee
                        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>Test.html</welcome-file>
  </welcome-file-list>

  <!-- RequestFactory Servlet -->

  <servlet>
    <servlet-name>requestFactoryServlet</servlet-name>
    <servlet-class>com.google.web.bindery.requestfactory.server.RequestFactoryServlet</servlet-class>
    <init-param>
      <param-name>symbolMapsDirectory</param-name>
      <!-- You'll need to compile with -extras and move the symbolMaps directory
           to this location if you want stack trace deobfuscation to work -->
      <param-value>WEB-INF/classes/symbolMaps/</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>requestFactoryServlet</servlet-name>
    <url-pattern>/gwtRequest</url-pattern>
  </servlet-mapping>

  <!-- Other servlets -->

  <servlet>
    <servlet-name>dataMessagingServlet</servlet-name>
    <servlet-class>
      com.google.android.c2dm.server.C2DMRetryServlet
    </servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>dataMessagingServlet</servlet-name>
      <url-pattern>/tasks/c2dm</url-pattern>
  </servlet-mapping>

  <!-- Security -->

  <!--  Require user login for the .html welcome page -->
  <security-constraint>
    <web-resource-collection>
      <url-pattern>/Test.html</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>*</role-name>
    </auth-constraint>
  </security-constraint>

  <!--  Require admin role for the tasks servlet -->
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>tasks</web-resource-name>
      <url-pattern>/tasks/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>admin</role-name>
    </auth-constraint>
  </security-constraint>

</web-app>

最佳答案

你做对了吗initialize RequestFactory 实例?

您似乎没有初始化RequestTransport:AbstractRequestContext.java:1102

关于java - AbstractRequestContext.doFire 处的 NullPointerException(AbstractRequestContext.java :1102),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8668874/

相关文章:

java - 共享除前缀之外的所有地点或如何使用 PlaceHistoryMapperWithFactory

java gwt 点击处理程序

javascript - 了解 Document.createElement()

java - Java中的MongoDB查询,在嵌套对象中搜索/查找

java - 如何使用嵌套 for 循环来创建向 Java 中的每一行添加附加列的行?

java - 将 java 实体映射到 GraphQL 对象

java - 在列表中映射 POJO 时,为什么 Cloud Endpoints 会抛出 com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException?

python - 谷歌应用程序引擎启动器上的应用程序错误

google-app-engine - 在 GAE 中,用户什么时候可能没有 ID

java - 为什么 Thymeleaf 代码在 HTML 的头部部分不起作用,但在正文中却能正常工作