8

私はGAEとクラウドエンドポイントを始めたばかりです。サンプルの永続クラスを作成し、Eclipseのgoogleメニューを使用してenpointクラスを生成しました。今、私はcurl素敵な文字列を使用して取り戻す方法についてのチュートリアルに従っていjsonましたが、すべての値をリストしようとするとnullpointerexception、驚くべきことに、URL文字列でIDを指定すると、魔法のように機能します。listContinentさて、私の懸念はこの2つの方法、つまりgetContinent

これがエラーの原因です

 curl http://localhost:8888/_ah/api/app/v1/continent

これは、エラーを発生させるメソッドを呼び出してlistContinentいます。

これはうまくいきます

 curl http://localhost:8888/_ah/api/app/v1/continent/1

これはメソッドを呼び出しており、URLを介してgetContinent正しいものIdが渡されると、期待どおりに機能します。

これは私のエンドポイントクラスです-

@Api(name = "app")
public class ContinentEndpoint {

    @SuppressWarnings({ "cast", "unchecked" })
    public List<Continent> listContinent() {
        PersistenceManager mgr = getPersistenceManager();
        List<Continent> result = new ArrayList<Continent>();
        try {
            Query query = mgr.newQuery(Continent.class);
            for (Object obj : (List<Object>) query.execute()) {
                result.add(((Continent) obj));
            }
        } finally {
            mgr.close();
        }
        return result;
    }

    public Continent getContinent(@Named("id") Long id) {
        PersistenceManager mgr = getPersistenceManager();
        Continent continent = null;
        try {
            continent = mgr.getObjectById(Continent.class, id);
        } finally {
            mgr.close();
        }
        return continent;
    }

    private static PersistenceManager getPersistenceManager() {
        return PMF.get().getPersistenceManager();
    }

}

これは私の永続的なクラスです-

@PersistenceCapable(identityType = IdentityType.APPLICATION)
@Version(strategy = VersionStrategy.VERSION_NUMBER)
public class Continent {

    public long getContinentId() {
        return continentId;
    }

    public void setContinentId(long continentId) {
        this.continentId = continentId;
    }

    public String getContinentName() {
        return continentName;
    }

    public void setContinentName(String continentName) {
        this.continentName = continentName;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private long continentId;
    private String continentName;
    private Date createdOn = new Date();
}

これは私のスタックトレースです

Nov 12, 2012 3:07:10 PM com.google.apphosting.utils.jetty.JettyLogger info
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger
Nov 12, 2012 3:07:10 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml
INFO: Successfully processed /home/soham/Workspace/cloudcv/war/WEB-INF/appengine-web.xml
Nov 12, 2012 3:07:10 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml
INFO: Successfully processed /home/soham/Workspace/cloudcv/war/WEB-INF/web.xml
Nov 12, 2012 8:37:11 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The server is running at http://localhost:8888/
Nov 12, 2012 8:37:11 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: The admin console is running at http://localhost:8888/_ah/admin
Nov 12, 2012 8:37:53 PM com.google.api.server.spi.SystemService invokeServiceMethod
SEVERE: null
java.lang.NullPointerException
    at com.google.appengine.datanucleus.query.QueryEntityPKFetchFieldManager.fetchLongField(QueryEntityPKFetchFieldManager.java:74)
    at org.datanucleus.identity.IdentityUtils.getApplicationIdentityForResultSetRow(IdentityUtils.java:101)
    at com.google.appengine.datanucleus.EntityUtils.entityToPojo(EntityUtils.java:1009)
    at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:228)
    at com.google.appengine.datanucleus.query.DatastoreQuery$2.apply(DatastoreQuery.java:225)
    at com.google.appengine.datanucleus.query.LazyResult.resolveNext(LazyResult.java:96)
    at com.google.appengine.datanucleus.query.LazyResult$LazyAbstractListIterator.computeNext(LazyResult.java:229)
    at com.google.appengine.datanucleus.query.AbstractIterator.tryToComputeNext(AbstractIterator.java:131)
    at com.google.appengine.datanucleus.query.AbstractIterator.hasNext(AbstractIterator.java:126)
    at com.google.appengine.datanucleus.query.LazyResult$AbstractListIterator.hasNext(LazyResult.java:183)
    at com.cloudcv.ContinentEndpoint.listContinent(ContinentEndpoint.java:23)
    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:616)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:115)
    at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:254)
    at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:135)
    at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:106)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.socket.dev.DevSocketFilter.doFilter(DevSocketFilter.java:74)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.ResponseRewriterFilter.doFilter(ResponseRewriterFilter.java:123)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:34)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:61)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:94)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:383)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

デバッグを行ったところ、のクエリがQuery query = mgr.newQuery(Continent.class);何も返さず、for eachループがにデータを入力していないことがわかりましたArrayList

4

1 に答える 1

21

long主キータイプとして使用することはできません。代わりに使用することをお勧めしLongます。受け入れ可能なキータイプについては、こちらをご覧ください。

于 2012-11-12T18:25:48.923 に答える