I am attempting to connect my android app to my backend endpoints (in Google's App Engine) so that I can store my java objects in Google's datastore. However when I try to initialize the PersistenceManagerFactory object, I get the error seen at the end of this post - The PersistenceManagerFactory class must define a static method.
I am trying to initialize the object using the following code, and note: I do have the library in the classpath.
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;
}
There is no line number listed in the error, however I am 90% sure the problem lies in the code above, or the class that I am using for the persistenceManagerFactory. The error when this code runs appears below. Any ideas? I really don't understand what the problem is....
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)
From the javax/jdo/Bundle.properties, we can see the below definition.
EXC_GetPMFNullPointerException = The PersistenceManagerFactory class must define a static methodPersistenceManagerFactory getPersistenceManagerFactory(Map props). The class "{0}" defines a non-static getPersistenceManagerFactory(Map props) method.
From the javax.jdo.JDOHelper source code, we can deduce that the below error message "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." is coming from the below code in invokeGetPersistenceManagerFactoryOnImplementation method.
catch (NullPointerException e) {
throw new JDOFatalInternalException (msg.msg("EXC_GetPMFNullPointerException", pmfClassName), e);}
This is caused by java.lang.NullPointerException at javax.jdo.JDOHelper.forName(Unknown Source), which is mostly probably coming form Class.forName(name, init, loader);
Anyway, you could modify the javax.jdo.JDOHelper.forName method to add some more traces & print more exception info in it. It's not difficult.
If requried, you tell me the version for "jdo-api", then, I could provide one for you.
Related
I have an issue binding a remote object to the RMI registry. I've reduced my code to a very simple example that works fine when I test it on my computer (Windows 10). But if I start it on another computer (Windows 7), when registry.bind(id, remoteObject); gets called, I get this exception:
java.lang.ClassNotFoundException:
rmitest.IRemote (no security manager: RMI class loader disabled)
I shouldn't need a SecurityManager since all class files are in the jar and I don't want to use the dynamic code loading feature.
Why does it try to load a security manager and why can't it find one even if I define one? What could be the reason that it works on one machine but not another? I think the code is ok and it must some configuration issue, but I'm not sure what exactly is configured wrong.
Here is the remote interface and remote object implementation, which I exported as runnable Jar in Eclipse as rmitest.jar.
public interface IRemote extends Remote {
void foo() throws RemoteException;
}
public class RemoteImpl extends UnicastRemoteObject implements IRemote {
private static Registry registry;
public RemoteImpl() throws RemoteException {
super();
}
public static void main(final String[] args) throws Exception {
try {
LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
} catch (final Exception e) {
// already created
}
registry = LocateRegistry.getRegistry(Registry.REGISTRY_PORT);
registry.bind(UUID.randomUUID().toString(), new RemoteImpl());
System.out.println("Binding successful");
}
#Override
public void foo() throws RemoteException {
System.out.println("foo");
}
}
Here is the full stack trace, it throws in the line where registry.bind gets called and is exactly the same when running with either of the following commands:
java -jar rmitest.jar or
java -Djava.security.manager -Djava.security.policy=policy -jar rmitest.jar
It's quite strange that apparently in both cases a security manager is required but even in the second case it can't find one.
Exception in thread "main" java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmitest.IRemote (no security manager: RMI class loader disabled)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:276)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:253)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:379)
at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
at rmitest.RemoteImpl.main(RemoteImpl.java:29)
Caused by: java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: rmitest.IRemote (no security manager: RMI class loader disabled)
at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.oldDispatch(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$256(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: rmitest.IRemote (no security manager: RMI class loader disabled)
at sun.rmi.server.LoaderHandler.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader$2.loadProxyClass(Unknown Source)
at java.rmi.server.RMIClassLoader.loadProxyClass(Unknown Source)
at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
at java.io.ObjectInputStream.readProxyDesc(Unknown Source)
at java.io.ObjectInputStream.readClassDesc(Unknown Source)
at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
... 15 more
Here is the policy file, which should allow everything:
grant {
permission java.security.AllPermission;
};
The problem was 'some other Java process' that was providing its own Registry, which didn't have access to your CLASSPATH. You would have found that if you had something better than an empty catch block for createRegistry().
The problem was some other Java process running which seemed to interfer with the registry binding. I don't know what this rogue process did exactly but killing it resolved the error. No security manager is needed and simply running the jar as usual works now.
I want to use ProGuard in my project. I activated the option minifyEnabled. When I open the activity that uses the library Retrofit2, the app crashes with:
Unable to create call adapter for interface retrofit2.Call
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gatafan.mydeen/com.gatafan.mydeen.ActivityPlaces}:
java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit2.Call
for method i.a
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2338)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2390)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5292)
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:824)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for interface retrofit2.Call
for method i.a
at retrofit2.ServiceMethod$Builder.a(Unknown Source)
at retrofit2.ServiceMethod$Builder.b(Unknown Source)
at retrofit2.ServiceMethod$Builder.a(Unknown Source)
at retrofit2.Retrofit.a(Unknown Source)
at retrofit2.Retrofit$1.invoke(Unknown Source)
at com.gatafan.mydeen.api.$Proxy1.a(Native Method)
at com.gatafan.mydeen.api.VenueManager.requestFoursquare(Unknown Source)
at com.gatafan.mydeen.ActivityPlaces.onCreate(Unknown Source)
at android.app.Activity.performCreate(Activity.java:5264)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2302)
... 11 more
Caused by: java.lang.IllegalArgumentException: Call return type must be parameterized as Call<Foo> or Call<? extends Foo>
at retrofit2.Utils.e(Unknown Source)
at retrofit2.ExecutorCallAdapterFactory.a(Unknown Source)
at retrofit2.Retrofit.a(Unknown Source)
at retrofit2.Retrofit.a(Unknown Source)
... 21 more
From the github page for Retrofit there is a section explaining what to do when using proguard:
PROGUARD
If you are using Proguard in your project add the following lines to your configuration:
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
try this configuration first, before moving forward with proguard changes
I want to set up Geneious program but I get following exception error:
Exception:
java.lang.NoSuchMethodException: No constructor for class com.install4j.api.context.OverwriteMode found
at com.install4j.runtime.xmldecode.Handler.endElement(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.endElement(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.element(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.element(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.element(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.element(Unknown Source)
at com.install4j.runtime.xmldecode.SaxOutputter.output(Unknown Source)
at com.install4j.runtime.xmldecode.XMLDecoder.initialize(Unknown Source)
at com.install4j.runtime.xmldecode.XMLDecoder.readObject(Unknown Source)
at com.install4j.runtime.installer.config.AbstractBeanConfig.instantiateBean(Unknown Source)
...
How can I fix this problem.
are you trying to call a constructor for OverwriteMode?
you should the enum constants: OverwriteMode.ALWAYS, OverwriteMode.NEVER, ... (found them all on linked page)
I'm trying to load a specific class using javassist, I'm doing this inside a pre-main method as the follwoing:
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined,
ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException
{
byte[] byteCode = classfileBuffer;
if(className.toLowerCase().endsWith("class1"))
{
ClassPool classPool = ClassPool.getDefault();
CtClass ctClass = classPool.get("com.class2");
}
}
but unfortuanetly, I'm getting a NotFoundException....
com.class2 is a class that will be loaded by the class loader after loading class1, but I nned to add a new method for class1 that has a return type of type com.class2
I tried all solutions inside stackoverflow.com but without any results.....
finally, both class1 and class2 are in the same package and inside the same JAR file, class1 has a member of type class2, but I have no idea why this classpool can't load the second one.
the stack trace here:
Exception: javassist.NotFoundException: com.Class2
javassist.NotFoundException: com.Class2
at javassist.ClassPool.get(ClassPool.java:439)
at javassist.ClassPool.getCtClass(ClassPool.java:504)
at com.stuff.MainAppletTransformer.transform(MainAppletTransformer.java:69)
at sun.instrument.TransformerManager.transform(Unknown Source)
at sun.instrument.InstrumentationImpl.transform(Unknown Source)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.defineClassHelper(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.access$100(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin2.applet.Plugin2ClassLoader.findClassHelper(Unknown Source)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Your method does not have a return value and would therefore not compile. I can however still tell what is going wrong: You are not setting up a correct search path. From your stack trace, it seems like you are running an applet which is shielded by a specific ClassLoader. This class loader is not visible to Javassist in your current version.
By using ClassPool.getDefault(), you are looking up information from the system class path. For your applet, you would probably need to add the class loader that is handed over by the transformatio method as an argument.
You can append a class loader to Javassist's search path by
ClassPool classPool = ClassPool.getDefault();
classPool.appendClassPath(new LoaderClassPath(classLoader));
After appending this path, your example should work.
I have a java applet which uses a proxy service to a WCF Service to display data. The applet compiles and runs perfectly in Eclipse but when I build and export a Jar file then run it in a html page it fails with
java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException.
I have included jaxrpc.jar in my build path and my jar file contains all necessary classes.
The stack trace seems to be complaining about the line where I instantiate the proxy service from within the applet class. Does anyone know if there is an issue calling WCF service from a java applet?
Stack Trace:
java.lang.RuntimeException: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter.instantiateApplet(Unknown Source)
at sun.plugin2.applet.Plugin2Manager.initAppletAdapter(Unknown Source)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoClassDefFoundError: javax/xml/rpc/ServiceException
at ListProducts.ListProducts.<init>(ListProducts.java:25)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at com.sun.deploy.uitoolkit.impl.awt.AWTAppletAdapter$1.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
at sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 27 more
This has been troubling me all day.
I think your issue is loading rpc jar, not call to wcf.
This post can be helpfull:
http://www.coderanch.com/t/259357/Applets/java/Applet-Axis-Client-Errors
It recomemds to sign your jar, verify you can access all your jars via browser, ensure you have all dependent.jars.
If all this will not help - i'd try to solve it as "
NoClassDefFoundError from spplet" issue.
Ok. I got this working by doing several things:
First I had to sign several of the jar files I was using:
jaxrpc.jar
axis.jar
commons-discovery-0.2.jar
but not:
javax.wsdl_1.6.2.v201012040545.jar
org.apache.commons.logging_1.0.4.v201101211617.jar
Secondly - all these files had to exist in the same directory as the html page, as I didn't specify a directory in codebase property for the applet tag.
Thirdly, within my main applet (ListProducts.class) I had to use AccessController.doPrivileged() around the code that first calls the proxy service:
EDIT: This step may not be necessary, as it now seems to work when I remove the doPrivileged block.
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
//instantiate proxy service and make rpc's
//do other stuff with results...
} catch (RemoteException e) {
// catch error
}
return null;
}
});
This combination of things got the java applet doing what it should. It was a painful slow process to discover which jar files were missing and then signing the appropriate ones.