[英]Google App Engine (Java) Datastore Statistics API causes error
I'm trying to implement Google App Engine's default Datastore Statistics API example: 我正在尝试实施Google App Engine的默认数据存储区统计API示例:
http://code.google.com/appengine/docs/java/datastore/stats.html 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. 尝试访问globalStat对象属性时收到java.lang.NullPointerException。 I'm testing locally, does this API only work in production or am I missing something?
我正在本地进行测试,此API是否仅在生产环境中有效?
Thanks 谢谢
If you look at the javadoc for the DatastoreService class, it doesn't look like there's a prepare method. 如果您查看DatastoreService类的javadoc ,就好像没有一个prepare方法。 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.
我相信您应该只使用get和put方法,其中get方法参数将是您要获取的内容的“键”,而put方法的参数将只是您创建的实体的对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.