Objectify文档(https://github.com/objectify/objectify/wiki/Entities)对我来说非常浅薄,只给出了一个在数据存储区中保存实体的示例。
我希望使用android studio在我的开发GAE服务器中保存一个名为 Presidents 的组下的5个实体。根据我对文档的理解,我应该这样做
@Entity
public class Presidents{
@Id Long id;
String name;
int age;
public Presidents(Long pId, String pName, int pAge){
id = pId;
name = pName
age = pAge;
}
}
然后我注册我的课程并像这样使用它(我使用junit来执行测试)
public PresidentsOfKenyaTest{
static{
ObjectifyService.register(Presidents.class);
}
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
@Before
public void setUp() {
helper.setUp();
}
@Test
Public void nameOfPresidents(){
Presidents p1 = new Presidents(new Long(1),Daniel,88);
Presidents p2 = new Presidents(new Long(2),Mwai,81);
Presidents p3 = new Presidents(new Long(3),Daniel,70);
ofy().save().entities.(p1,p2,p3).now();
}
@After
public void tearDown() {
helper.tearDown();
}
}
然而,当我在android studio中运行上述类的Junit测试时,我得到了下面的例外
java.util.ServiceConfigurationError:com.google.appengine
.tools.development.LocalRpcService: Provider com.google.appengine.api.
datastore.dev.LocalCloudDatastoreV1Service could not be instantiated
at PresidentsOfKenyaTest.tearDown(PresidentsOfKenyaTest.java:40)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.google.appengine.api.datastore.dev.LocalCloudDatastoreV1Service
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 40 more
问题