gpt4 book ai didi

java - PersistenceManagerFactory 类必须定义一个静态方法?

转载 作者:行者123 更新时间:2023-11-30 02:43:40 24 4
gpt4 key购买 nike

我正在尝试将我的 android 应用程序连接到我的后端端点(在 Google 的 App Engine 中),以便我可以将我的 java 对象存储在 Google 的数据存储区中。但是,当我尝试初始化 PersistenceManagerFactory 对象时,出现了本文末尾的错误 - PersistenceManagerFactory 类必须定义静态方法

我正在尝试使用以下代码初始化对象,并注意:类路径中确实有库。

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)

最佳答案

javax/jdo/Bundle.properties,我们可以看到下面的定义。
EXC_GetPMFNullPointerException = PersistenceManagerFactory 类必须定义静态方法PersistenceManagerFactory getPersistenceManagerFactory(Map props)。 “{0}”类定义了一个非静态 getPersistenceManagerFactory(Map props) 方法。

javax.jdo.JDOHelper源代码,我们可以推断出下面的错误信息“The PersistenceManagerFactory class must define a static method PersistenceManagerFactory getPersistenceManagerFactory( Map props)org.datanucleus.jdo.JDOPersistenceManagerFactory 类定义了一个非静态 getPersistenceManagerFactory(Map props) 方法。”来自 invokeGetPersistenceManagerFactoryOnImplementation 方法中的以下代码。

    catch (NullPointerException e) {
throw new JDOFatalInternalException (msg.msg("EXC_GetPMFNullPointerException", pmfClassName), e);}

这是由 javax.jdo.JDOHelper.forName(Unknown Source) 处的 java.lang.NullPointerException 引起的,这很可能来自 Class。 forName(名称, 初始化, 加载器);
无论如何,您可以修改 javax.jdo.JDOHelper.forName 方法以添加更多跟踪并在其中打印更多异常信息。这并不难。
如果需要,你告诉我“jdo-api”的版本,然后,我可以为你提供一个。

关于java - PersistenceManagerFactory 类必须定义一个静态方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25414210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com