I tried to reproduce the attempt to make a capture of a window following :
Java - Window Image
(2 years old post)
I'm using JNA 3.5.0 and tested the unmodified code under XP and 7 with jre 7, and both failed with the same trace :
Exception in thread "main" java.lang.AbstractMethodError:
com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
at com.sun.jna.Structure.fieldOrder(Structure.java:831)
at com.sun.jna.Structure.getFields(Structure.java:857)
at com.sun.jna.Structure.deriveLayout(Structure.java:983)
at com.sun.jna.Structure.calculateSize(Structure.java:908)
at com.sun.jna.Structure.calculateSize(Structure.java:896)
at com.sun.jna.Structure.allocateMemory(Structure.java:357)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.platform.win32.WinDef$RECT.<init>(WinDef.java:320)
at Paint.capture(Paint.java:24)
at Paint.<init>(Paint.java:71)
at Paint.main(Paint.java:64)
To reproduce it simply just run :
import com.sun.jna.platform.win32.WinDef.RECT;
public class Test {
public static void main(String[] args) {
RECT rect = new RECT();
}
}
If I understand JNA correctly, com.sun.jna.platform.win32.WinDef should be mapped to a system DLL by default.
It seems that the mapping is not correctly done.
I tried to figure out how to map WinDef to needed dll but couldn't find out how to do this with com.sun.jna.Native.loadLibrary method.
I don't understand why a AbstractMethodError is thrown instead of an UnsatisfiedLinkError, so I'm not sure the library loading is really the problem.
Instanciating com.sun.jna.Structure causes the exception, bug I didn't find any information on wether it could be fixed by a native library loading or it is a bug that has another cause.
I thought it could be Windows rights (admin) that my application doesn't acquire.
Or maybe I have to explicitely precise some pathes to jna so that he can find the dlls (but as I said before, it is no UnsatisfiedLinkError so it shouldn't be that).
If you have any experience with JNA and can give me some advice, please answer me.
Given the stacktrace, the understanding of JNA libraries I acquired so far, hours of searches and javadoc exploring, I obviously missed something that a JNA average user could probably find it (the original post is qualified of "Working example").
By the way, if you have any links or resources about jna (didn't find many), please post them :)
Thanks in advance !
I don't know why but it works for me with JNA 3.4.0.
You can find it on MavenRepository http://mvnrepository.com/artifact/net.java.dev.jna
Thanks for your attention
The first line of the error
Exception in thread "main" java.lang.AbstractMethodError:
nearly always indicates a linkage error, that you're using incompatible versions of something.
In this specific case, it appears that platform.jar file released in JNA 3.5.0 was not properly updated.
Related
Springboot occassionally occur following errors:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.security.jca.ProviderConfig$ProviderLoader
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:244)
at java.base/sun.security.jca.ProviderConfig$3.run(ProviderConfig.java:238)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/sun.security.jca.ProviderConfig.doLoadProvider(ProviderConfig.java:238)
at java.base/sun.security.jca.ProviderConfig.getProvider(ProviderConfig.java:218)
at java.base/sun.security.jca.ProviderList.getProvider(ProviderList.java:266)
at java.base/sun.security.jca.ProviderList$ServiceList.tryGet(ProviderList.java:511)
at java.base/sun.security.jca.ProviderList$ServiceList$1.hasNext(ProviderList.java:565)
at java.base/javax.crypto.SecretKeyFactory.nextSpi(SecretKeyFactory.java:301)
at java.base/javax.crypto.SecretKeyFactory.<init>(SecretKeyFactory.java:121)
at java.base/javax.crypto.SecretKeyFactory.getInstance(SecretKeyFactory.java:168)
at com.kingbase8.shaded.com.ongres.scram.common.ScramMechanisms.saltedPassword(ScramMechanisms.java:155)
at com.kingbase8.shaded.com.ongres.scram.common.ScramFunctions.saltedPassword(ScramFunctions.java:59)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ClientFinalProcessor.<init>(ScramSession.java:196)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ClientFinalProcessor.<init>(ScramSession.java:163)
at com.kingbase8.shaded.com.ongres.scram.client.ScramSession$ServerFirstProcessor.clientFinalProcessor(ScramSession.java:130)
JDK information as following:
enter image description here
Ah, please try to search the log, it is possible a ExceptionInInitializerError was happened before, so this time the JVM throws NoClassDefFoundError directly because it was failed last time.
Need to get the call stack of the original ExceptionInInitializerError (if it exists) in order to fix this issue.
Related codes and links
https://github.com/openjdk/jdk11u/blob/jdk-11+28/src/java.base/share/classes/sun/security/jca/ProviderConfig.java#L308 - the class ProviderConfig$ProviderLoader was defined inside OpenJDK 11 so it is not likely to a Java classpath issue
https://stackoverflow.com/a/5756989/2412606 - See definition of NoClassDefFoundError here. thanks to #oldpeculier and #jared
For this problem not very clear why occur. in order to fix the problem. we can manual use Security.addSecurity method to load jca or analogous component again. like BouncyCastle. now it work fine for me.
I was using Java 11 and the project was build using Java 1.8. Once I switched to Java 1.8 it worked fine
I'm running Cassandra 2.2.11 (and won't be upgrading) on a host. Periodically, in a cron job, I run nodetool commands for monitoring. nodetool is implemented as just another java process that uses JMX to talk to the Cassandra java process. I launch five or so commands every minute.
Once in a while (not in any recognizable pattern), the execution of nodetool will fail with a NoClassDefFoundError that refers to a class from java.lang. For example,
java.lang.NoClassDefFoundError: java/lang/Thread (wrong name: java/lang/Thread)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredField(Class.java:2068)
at java.util.concurrent.FutureTask.<clinit>(FutureTask.java:476)
at java.util.concurrent.ScheduledThreadPoolExecutor.scheduleWithFixedDelay(ScheduledThreadPoolExecutor.java:590)
at sun.rmi.transport.tcp.TCPChannel.free(TCPChannel.java:347)
at sun.rmi.server.UnicastRef.free(UnicastRef.java:431)
at sun.rmi.server.UnicastRef.done(UnicastRef.java:448)
at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source)
at com.sun.jndi.rmi.registry.RegistryContext.lookup(RegistryContext.java:132)
at com.sun.jndi.toolkit.url.GenericURLContext.lookup(GenericURLContext.java:205)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at javax.management.remote.rmi.RMIConnector.findRMIServerJNDI(RMIConnector.java:1955)
at javax.management.remote.rmi.RMIConnector.findRMIServer(RMIConnector.java:1922)
at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:287)
at javax.management.remote.JMXConnectorFactory.connect(JMXConnectorFactory.java:270)
at org.apache.cassandra.tools.NodeProbe.connect(NodeProbe.java:183)
at org.apache.cassandra.tools.NodeProbe.<init>(NodeProbe.java:150)
at org.apache.cassandra.tools.NodeTool$NodeToolCmd.connect(NodeTool.java:302)
at org.apache.cassandra.tools.NodeTool$NodeToolCmd.run(NodeTool.java:242)
at org.apache.cassandra.tools.NodeTool.main(NodeTool.java:158)
In this stack trace, the error happens during class initialization for FutureTask. I've also seen
java.lang.NoClassDefFoundError: java/lang/Object (wrong name: java/lang/Object)
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.getDeclaredMethod(Class.java:2128)
at java.lang.invoke.MethodHandleImpl$Lazy.<clinit>(MethodHandleImpl.java:614)
[...]
but also
java.lang.NoClassDefFoundError: java/lang/String (wrong name: java/lang/String)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredField(Class.java:2068)
at java.io.ObjectStreamClass.getDeclaredSUID(ObjectStreamClass.java:1703)
at java.io.ObjectStreamClass.access$700(ObjectStreamClass.java:72)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:484)
at java.io.ObjectStreamClass$2.run(ObjectStreamClass.java:472)
[...]
So it's not only happening during class initialization, but, in the few samples I've collected, something in the reflection implementation does seem to be the culprit.
Java is at version 8
java version "1.8.0_144"
The nodetool launcher always uses the same classpath. And there are no weird classes in there (or additional class loaders). The same installation is done across hundreds of identical nodes (on Linux).
My top search results for NoClassDefFoundError wrong name refer to executions where a simplified class name was used to launch java, rather than the fully qualified name. That's not the issue here. Also, the names in the error messages are identical.
So what can cause such "wrong name" NoClassDefFoundError errors for "bootstrap" classes?
i think it is the lack of resource that cause the problems like the connector timeout or something. Do you see the log from your example?;
nodeprobe is connecting through the jmx or trying to connect then the error occurs?
Those are very typical error that can also cause other intermiten error on the shit.(usually OS/netowrk OS shit) thus :
includes your string and even object based error ;in conclusion it make sense.
may be you should check your resource when the error happen.
i know this is kind of catch 22 that the resource monitor is causing the lack of resource instead; but it happen hehe
According to the stacktraces, the exception id being thrown in a calls to getDeclaredFields0. However, this is not where the exception came from originally. According to the OpenJDK source code, there is nothing in the codebase that throws an exception with "wrong name" in the exception message. The message has come from somewhere else.
I strongly suspect that this is actually re-reporting a problem that happened the first time that some class was loaded or initialized. What happens is that the classloader finds the problem the first time, marks the offending internal class object as "bad" and then the throws the error. According to the javadoc, applications should not attempt to recover from this. But if one does, and then attempts to use the "bad" class in some way, the original problem will be reported again as a NoClassDefFoundError with the original reason.
So what does the reason mean?
It is hard to tell because we don't have the stacktrace for the original exception; i.e. then one where the classloading / initialization first failed. If you can find that stacktrace, we can track down the 3rd-party library that did it. It is almost certainly happening in a classloader.
The obvious meaning is that a class file has a classname in it that doesn't match the name in the classes bytecodes. However, we'd need to examine the classloader code to be sure.
So why is it happening intermittently?
Possibly because the application JVM has many classloaders and only a subset of them have "polluted" their class namespace with this bad class.
That could be bad news. It suggests there may be some kind of synchronization issue in the core of the application.
Anyhow, there is not enough evidence to draw sound conclusions.
Bottom line
Based on the evidence, I would guess that this is a result of some kind of "code weaving" or "byte code engineering" that has gone wrong. As a further guess, I would say that some child classloader is not delegating properly, and has mistakenly attempted to process a built-in class. (It could even be that the classloader in question knows that it should never process a "java.lang.*" class and it has a obscure way of saying this.)
Why? possibly because someone / something explicitly added the "rt.jar" to some classpath that it shouldn't be on.
For further diagnosis, the first thing we need is the original stacktrace that tells us which classloader did the initial damage.
As none of basic java library found,I think there is problem in your java installation or you have not set CLASSPATH and JAVA_HOME environment variables. Try to set CLASSPATH and JAVA_HOME environment variables.
export JAVA_HOME="/usr/lib/jvm/java-8-oracle/bin"
export CLASSPATH="/usr/lib/jvm/java-8-oracle/lib"
If not worked, try reinstall java and set environment variables.
I keep getting java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
The full stacktrace is:
java.lang.NoClassDefFoundError: Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:108)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:69)
net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:57)
net.sf.jasperreports.engine.fill.JRFiller.createBandReportFiller(JRFiller.java:200)
net.sf.jasperreports.engine.fill.JRFiller.createReportFiller(JRFiller.java:215)
net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:115)
net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:583)
net.sf.jasperreports.engine.JasperRunManager.runToPdf(JasperRunManager.java:455)
net.sf.jasperreports.engine.JasperRunManager.runReportToPdf(JasperRunManager.java:870)
com.evnica.interop.main.ReportServlet.createReport(ReportServlet.java:119)
com.evnica.interop.main.ReportServlet.doGet(ReportServlet.java:96)
com.evnica.interop.main.ReportServlet.service(ReportServlet.java:79)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
I have searched for the solution and found a bunch.
Could not initialize class net.sf.jasperreports.engine.util.JRStyledTextParser
JasperReports NoClassDefFoundError exception on net.sf.jasperreports.engine.util.JRStyledTextParser
and about 10 more (this is my first question so I can't enlist them all).
I have tried:
To set java.awt.headless=true.
I did it within code:
static {
System.setProperty("java.awt.headless", "true");
System.out.println(java.awt.GraphicsEnvironment.isHeadless());
}
(returns true as expected).
I did it in JVM Options:
I set CATALINA_OPTS to -Djava.awt.headless=true. Echoes as expected.
It didn't help.
I tested it with.jrxml with DejaVu Sans and included jasperreports-fonts-6.2.2.jar in the path, and I tested it with Sans Serif. I checked which fonts were available to JVM and tested with them. No success.
There were suggestions to check versions of jasperreports jars - I checked it too. I have all the jars of 6.2.2. version:
jasperreports-6.2.2.jar,
jasperreports-fonts-6.2.2.jar,
jasperreports-javaflow-6.2.2.jar.
I use joda-time-2.9.3 (have no idea how it's connected to the problem, but one advice was to use joda; I used it from the beginning anyway), project SDK is java 1.8.0_51 (there was an advice to update to 8 - not relevant as I already use it), and my Tomcat is OK (the absent work folder caused similar problem in one of the cases).
What am I missing?
EDIT:
While debugging I came to a method initializeGrophEnv() in JRGraphEnvInitializer class, which throws a util.graphic.environment.initialization.error:
AVAILABLE_FONT_FACE_NAMES.addAll(Arrays.asList(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()));
It's interesting that the method getAvailableFontFamilyNames() in SunGraphicsEnvironment returns a valid array of 274 elements (printscreen from debugger under link):
First of all, thanks everyone for help. You responded so fast, and made me dig deeper =) The problem is solved.
My error was to have both jasperreports-6.2.2.jar and jasperreports-javaflow-6.2.2.jar in the libraries. As you remember, the last method in the stack trace was the initialization of JRBaseFiller. The presence of two jars caused a conflict, as both contain a package net.sf.jasperreports.engine.fill with a JRBaseFiller class in it.
I left the jasperreports-javaflow-6.2.2.jar only. It didn't work on its own. I added two more libraries: jfreechart-1.0.19.jar (previous versions didn't contain all the needed classes) and jcommon-1.0.8. The java.lang.NoClassDefFoundError is gone.
We have coded and run a dynamic web application using MAPSERVER(Version 6.0.1) on windows platform using Java Technology. Now, there is need of deploying it on Ubuntu 11.10. We have installed Apache Tomcat 6.0, Mapserver 6.0.1, Apache 2.0, and FWTools-2.0.1(As this package contain all required tools for mapserver if I am not wrong, so I didn't feel any other tools to be installed). We have deployed the war file(and put application without) in Apache Tomcat 's Webapps folder. I even got the index page which dont have code related with mapscript api. But while fetching the other servlet with mapscript we are getting following error...
java.lang.UnsatisfiedLinkError: no mapscript in java.library.path
java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
java.lang.Runtime.loadLibrary0(Runtime.java:840)
java.lang.System.loadLibrary(System.java:1047)
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
Again while refreshing the browser page where the above error was displayed, I got a change,
java.lang.NoClassDefFoundError: Could not initialize class
edu.umn.gis.mapscript.mapscriptJNI
edu.umn.gis.mapscript.mapObj.<init>(mapObj.java:283)
I searched on net about the above problem. But finally blank. Please, provide idea about the above problem.
I'm not going to explain why you're getting the UnsatisfiedLinkError, but instead I'll explain why you are getting the NoClassDefFoundError when you reload the page.
A NoClassDefFoundError with a message Could not initialize class ... is thrown by the JVM when it attempts to initialize a class that it has already tried and failed to initialize.
The first of your two stacktraces contains the line
edu.umn.gis.mapscript.mapscriptJNI.<clinit>(mapscriptJNI.java:23)
The method name <clinit> denotes the static initializer, of the class mapscriptJNI. So, at the point that the UnsatisfiedLinkError was thrown, the JVM was trying to initialize this class. Looking at the error message, it seems that this static initializer tried to load the native code library mapscript but failed.
This UnsatisfiedLinkError causes the mapscriptJNI class to fail to initialize successfully. The JVM keeps a record of all classes that fail to initialize, and if you attempt to initialize one of those classes again, you'll get a NoClassDefFoundError with a message saying that it could not initialize that class.
When you refresh the page, you end up causing the JVM to attempt to initialize the class mapscriptJNI a second time. Of course, this class failed to initialize the previous time. Your second stacktrace contains exactly the error I've described.
In short, the UnsatisfiedLinkError is the real error here. Fix that and the other one will go away.
I would check the following 2 items:
Is the mapscript.jar file on Tomcat or at least your webapp's classpath? (NoClassDefFoundError is your big clue here)
Is the libmapscript.so on either your LD_LIBRARY_PATH or -Djava.library.path? (UnsatisfiedLinkError since the shared object cannot be found)
Try having a look at this post, near the Running Java Mapscript (on Linux) section.
Hope that helps!
In Eclipse I get this eror:
Exception in thread "main"
java.lang.UnsatisfiedLinkError:
com.nokia.mid.impl.isa.util.SharedObjects.nativeSetTable(Ljava/util/Hashtable;)Ljava/util/Hashtable;
I can see SharedObjects, but nativeSetTable doesn't seem to be a method. It might however be hidden -> I don't have access to the source code.
This was my code:
connection = (HttpConnection)Connector.open(this.url);
This is the trace:
Exception in thread "main" java.lang.UnsatisfiedLinkError:
com.nokia.mid.impl.isa.util.SharedObjects.nativeSetTable(Ljava/util/Hashtable;)Ljava/util/Hashtable;
at
com.nokia.mid.impl.isa.util.SharedObjects.nativeSetTable(Native
Method) at
com.nokia.mid.impl.isa.util.SharedObjects.createTable(SharedObjects.java:465)
at
com.nokia.mid.impl.isa.util.SharedObjects.(SharedObjects.java:181)
at
com.nokia.mid.impl.isa.io.GeneralSharedIO.(GeneralSharedIO.java:67)
at
com.sun.midp.io.ConnectionBaseAdapter.checkForPermission(ConnectionBaseAdapter.java:236)
at
com.sun.midp.io.ConnectionBaseAdapter.openPrim(ConnectionBaseAdapter.java:205)
at
com.sun.midp.io.ConnectionBaseAdapter.openPrim(ConnectionBaseAdapter.java:178)
at
com.sun.midp.io.InternalConnector.openPrim(InternalConnector.java:254)
at
com.sun.midp.io.InternalConnector.open(InternalConnector.java:153)
at
javax.microedition.io.Connector.open(Connector.java:138)
at
javax.microedition.io.Connector.open(Connector.java:120)
at
javax.microedition.io.Connector.open(Connector.java:104)
I think that nativeSetTable() is protected or private, that's why you don't see it. And moreover nativeSetTable() is a native method, which means that it is based on native code (already compiled for a specific processor and available in a specific lib [ie. a DLL]).
UnsatisfiedLinkError means that this particular method couldn't be retrieved and executed properly.
Thrown if the Java Virtual Machine cannot find an appropriate native-language definition of a method declared native.
This means that your Java ME emulator must have missing librairies. You should try to reinstall it.
Resources :
Javadoc - UnsatisfiedLinkError
I guess you are coupling your source code with the wrong version of the nokia mid library.
It could be that your runtime classpath is using a different version of the jar where SharedObjects lives, when compared to your compile-time classpath in Eclipse. I would double-check your classpath settings.
Ok, I found one reason:
I created a test class in java to test my code, just a plain java file (with main method). And I ran it as a plain java application. Then, it doesn't work. But after I tried it in a Midlet, I didn't get the error!