简体   繁体   中英

Google App Engine (Java) Datastore Statistics API causes error

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM