对应用引擎端点的Objectify OfyService NoClassDefFoundError

时间:2015-10-11 09:36:30

标签: android google-app-engine google-cloud-endpoints objectify

我的android-appengine-endpoint项目完全由android studio设置。因此我不会乱用任何东西:我只是让android studio将我的AppEngine模块添加到我的android项目中。现在我得到一个Dim i As Integer, c As Range i = 1 For Each c In Range("A1:A10") If Len(c.Value) = 0 Then Sheets("Data").Range("K" & c.Row).Value = i i = i + 1 End If Next c 。我是否必须在gradle中设置某些东西或在android studio中配置一些东西来摆脱这个错误?基本上当我尝试测试我的应用程序时,我得到了例外。

代码:

注意:UserDao不是在我的端点类中调用java.lang.NoClassDefFoundError,而是进行所有ofy数据访问调用的地方。您可以将我的代码与{ {3}}

ofy

从App Engine控制台看到的实际错误:

public class UserDao extends OfyService {
    public static void persist(User user) {
        ofy().save().entities(user).now();
    }
    public static User getById(long id) {
        return ofy().load().type(User.class).id(id).now();
    }
    public static List<User> getByTwitterId(Long twitterId) {
        return ofy().load().type(User.class).filter("twitterId", twitterId).list();
    }
}

public class OfyService {
    public OfyService() {}

    static {
        ObjectifyService.register(User.class);
        ObjectifyService.register(Food.class);
        ObjectifyService.register(Pet.class);
    }

    public static Objectify ofy() { return ObjectifyService.ofy(); }

    public static ObjectifyFactory factory() {
        return ObjectifyService.factory();
    }
}

我在这里看到的每篇文章似乎都在讨论com.google.api.server.spi.SystemService invokeServiceMethod: exception occurred while calling backed method java.lang.NoClassDefFoundError: Could not initialize class com.mycompany.server.data.dao.UserDao at com.mycompany.server.utils.Authenticator.verifyAccount(Authenticator.java:22) at com.mycompany.server.endpoint.server.getFood(server.java:105) at sun.reflect.GeneratedMethodAccessor22.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:44) at com.google.api.server.spi.SystemService.invokeServiceMethod(SystemService.java:359) at com.google.api.server.spi.SystemServiceServlet.execute(SystemServiceServlet.java:160) at com.google.api.server.spi.SystemServiceServlet.doPost(SystemServiceServlet.java:118) 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.googlecode.objectify.ObjectifyFilter.doFilter(ObjectifyFilter.java:48) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157) 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 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.headerComplete(HttpConnection.java:923) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:437) at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:444) at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:230) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:308) at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:300) at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:441) at java.lang.Thread.run(Thread.java:745) 。 Android Studio没有在我的WEB-INF中创建任何lib目录。所以Android Studio和App Engine都来自Google。因此,我在那里迷路了。

我的WEB-INF\lib只有三个文件:

  • webapp/WEB-INF
  • web.xml
  • logging.properties

以下是我的依赖项的图片,以防它有用:

this tutorial

2 个答案:

答案 0 :(得分:2)

由于您使用的是Cloud Endpoint,请执行以下操作:

  1. 在您的Endpoint类中,创建一个构造函数。
  2. 在构造函数中,调用new OfyService()
  3. 这可能有用的原因是你需要在需要使用它们之前加载所有客观化的相关类(即在客户端进行第一次调用之前的方式)。现在你在需要它们之前加载它们。 App-Engine类加载器中的延迟可能会让您感到沮丧。令人遗憾的是,您使用的结构非常受欢迎,因此大多数人都这样使用它:但不能保证它始终有效。这是竞争条件的事情。 App-engine加载类可能非常慢。幸运(或不幸),你很早就发现了问题。人们应该为你的痛苦提供一些支持:)。

答案 1 :(得分:1)

正如我从讨论中发现的那样,Objectify未能以未知原因注册课程。

也许,

  1. 您的某个数据类上的注释不正确(提供UserFoodPet的源代码以供进一步调查);
  2. 或同时从另一个线程调用OfyService方法(这不太可能)。
相关问题