我正在尝试将我的Android应用程序连接到我的后端端点(在Google的App Engine中),这样我就可以将我的java对象存储在Google的数据存储区中。但是,当我尝试初始化PersistenceManagerFactory
对象时,我会在此帖子末尾看到错误 - The PersistenceManagerFactory class must define a static method
。
我正在尝试使用以下代码初始化对象,并注意:我在类路径中确实有这个库。
public static PersistenceManagerFactory InitializePersistanceManagerClass(){
Properties properties = new Properties();
properties.setProperty("javax.jdo.PersistenceManagerFactoryClass", "org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
properties.setProperty("javax.jdo.option.ConnectionURL", "appengine");
properties.setProperty("javax.jdo.option.NontransactionalRead", "true");
properties.setProperty("javax.jdo.option.NontransactionalWrite", "true");
properties.setProperty("javax.jdo.option.RetainValues", "true");
properties.setProperty("datanucleus.appengine.autoCreateDatastoreTxns", "true");
properties.setProperty("datanucleus.appengine.singletonPMFForName", "true");
PersistenceManagerFactory pmf = JDOHelper.getPersistenceManagerFactory(properties);
return pmf;
}
错误中没有列出行号,但我90%确定问题出在上面的代码中,或者我用于persistenceManagerFactory
的类。此代码运行时出现的错误如下所示。有任何想法吗?我真的不明白问题是什么......
08-23 09:10:31.826 7932-7932/com.myApp.myModule E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.myApp.myModule, PID: 7932
javax.jdo.JDOFatalInternalException: The PersistenceManagerFactory class must define a static method
PersistenceManagerFactory getPersistenceManagerFactory(Map props).
The class "org.datanucleus.jdo.JDOPersistenceManagerFactory"
defines a non-static getPersistenceManagerFactory(Map props) method.
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(Unknown Source)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
at com.myApp.myModule.forStorage.PMF.<init>(Unknown Source)
at com.myApp.myModule.Login.onConnected(Unknown Source)
at wz.a(Unknown Source)
at rb.e(Unknown Source)
at rb.d(Unknown Source)
at rd.onConnected(Unknown Source)
at wz.a(Unknown Source)
at wz.a(Unknown Source)
at wy.a(Unknown Source)
at wy.a(Unknown Source)
at wv.b(Unknown Source)
at wu.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
at dalvik.system.NativeStart.main(Native Method)
NestedThrowablesStackTrace:
java.lang.NullPointerException
at javax.jdo.JDOHelper.forName(Unknown Source)
at javax.jdo.JDOHelper.invokeGetPersistenceManagerFactoryOnImplementation(Unknown Source)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
at javax.jdo.JDOHelper.getPersistenceManagerFactory(Unknown Source)
at com.myApp.myModule.forStorage.PMF.<init>(Unknown Source)
at com.myApp.myModule.Login.onConnected(Unknown Source)
at wz.a(Unknown Source)
at rb.e(Unknown Source)
at rb.d(Unknown Source)
at rd.onConnected(Unknown Source)
at wz.a(Unknown Source)
at wz.a(Unknown Source)
at wy.a(Unknown Source)
at wy.a(Unknown Source)
at wv.b(Unknown Source)
at wu.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:852)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:668)
at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
从javax/jdo/Bundle.properties
,我们可以看到以下定义
EXC_GetPMFNullPointerException
= PersistenceManagerFactory
类必须定义静态方法PersistenceManagerFactory getPersistenceManagerFactory(Map props)
。类“{0}”定义了非静态getPersistenceManagerFactory(Map props)
方法。
从javax.jdo.JDOHelper
源代码中,我们可以推断出以下错误消息“PersistenceManagerFactory
类必须定义静态方法PersistenceManagerFactory getPersistenceManagerFactory(Map props)
。类org.datanucleus.jdo.JDOPersistenceManagerFactory
定义非-static getPersistenceManagerFactory(Map props)
方法。“来自invokeGetPersistenceManagerFactoryOnImplementation
方法中的以下代码。
catch (NullPointerException e) {
throw new JDOFatalInternalException (msg.msg("EXC_GetPMFNullPointerException", pmfClassName), e);}
这是由java.lang.NullPointerException
javax.jdo.JDOHelper.forName(Unknown Source)
导致的,Class.forName(name, init, loader);
很可能来自javax.jdo.JDOHelper.forName
无论如何,你可以修改{{1}}方法来添加更多的痕迹&amp;在其中打印更多异常信息。这并不困难。
如果需要,你告诉我“jdo-api”的版本,那么,我可以为你提供一个。