Google App Engine (Java) 数据存储统计 API 导致错误
我正在尝试实现 Google App Engine 的默认数据存储区统计 API 示例:
http: //code.google.com/appengine/docs/java/datastore/stats.html
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query;
// ...
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity globalStat = datastore.prepare(new Query("__Stat_Total__")).asSingleEntity();
Long totalBytes = (Long) globalStat.getProperty("bytes"); // NullPointerException happens here...
Long totalEntities = (Long) globalStat.getProperty("count");
尝试访问 globalStat 对象属性时出现 java.lang.NullPointerException。我正在本地测试,这个 API 只在生产环境中有效还是我遗漏了一些东西?
谢谢
I'm trying to implement Google App Engine's default Datastore Statistics API example:
http://code.google.com/appengine/docs/java/datastore/stats.html
import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Query;
// ...
DatastoreService datastore = DatastoreServiceFactory.getDatastoreService();
Entity globalStat = datastore.prepare(new Query("__Stat_Total__")).asSingleEntity();
Long totalBytes = (Long) globalStat.getProperty("bytes"); // NullPointerException happens here...
Long totalEntities = (Long) globalStat.getProperty("count");
I get a java.lang.NullPointerException when trying to access the globalStat object properties. I'm testing locally, does this API only work in production or am I missing something?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 javadoc DatastoreService 类,看起来没有准备方法。我相信您应该只使用 get 和 put 方法,其中 get 方法参数将是您想要获取的内容的“关键”,而 put 方法的参数将只是您创建的实体的对象。
If you look at the javadoc for the DatastoreService class, it doesn't look like there's a prepare method. I believe you are supposed to just use the get and put methods, where the get methods parameters would be the "key" for what you're trying to get, and the put method's parameter would just be the entity you created's object.