I have to find system information in an applications and for this I have two native library files as given below:
SystemManagerLinux.so and SystemManagerWin32.dll.
I have to use these library files in my java code to show the information on java GUI. I have put these files on the location: C:\Users\surjit\Documents\NetBeansProjects\SampleMonitor and give it is as vm argument in my netbeans ide on run option as given below:
-Djava.library.path="C:\Users\surjit\Documents\NetBeansProjects\SampleMonitor"
and call the libraries as in the code :
if (os.startsWith("Linux"))
loadTmpLibrary("SystemManagerLinux.so", "libSML", ".so");
else if (os.startsWith("Windows")) {
loadTmpLibrary("SystemManagerWin32.dll", "SMW", ".dll");
But when I am running the application it is giving following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: SystemManagerWin32.fetchProcessIDs([I)I
at SystemManagerWin32.fetchProcessIDs(Native Method)
at SystemMonitor.refreshPidList(SystemMonitor.java:168)
at SystemMonitor.<init>(SystemMonitor.java:383)
at SystemMonitor.main(SystemMonitor.java:494)
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: SystemManagerWin32.fetchSystemMemoryStatus(LSystemMemoryStatus;)Z
at SystemManagerWin32.fetchSystemMemoryStatus(Native Method)
at SystemMonitor.run(SystemMonitor.java:410)
at java.lang.Thread.run(Thread.java:722)
Please suggest me solution.Thanks
The problem appears to be that the native methods you're attempting to call don't exist in your DLL, not that your DLL fails to be loaded.
Assuming loadTmpLibrary effectively performs a System.loadLibrary() call, you need to ensure that your native methods are declared properly. Usually invoking javah on the Java source which includes the native declarations is sufficient to get an accurate header. Compare its output with whatever it is you're currently compiling.
Related
I am having Aparapi translating Java code to OpenCL. However I wonder how I can see the generated OpenCL code. The website says "by using adding -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true to your command line when you start your JVM". Being new to this technology, I am not sure how exactly you can do this? Can anyone please help by elaborating the process?
Added part:
Thank you. But what should I do in case of hadoop? I am trying to generate the OpneCL code for a hadoop program that I am running this way:
hadoop jar .java
I have tried adding -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true before and after jar word, both did not work. Here is what I got.
Exception in thread "main" java.io.IOException: Error opening job jar: -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true
at org.apache.hadoop.util.RunJar.main(RunJar.java:90)
Caused by: java.io.FileNotFoundException: -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true (No such file or directory)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.(ZipFile.java:215)
at java.util.zip.ZipFile.(ZipFile.java:145)
at java.util.jar.JarFile.(JarFile.java:153)
at java.util.jar.JarFile.(JarFile.java:90)
at org.apache.hadoop.util.RunJar.main(RunJar.java:88)
Just add the property to the command line which you use to start java.
Specifically somewhere you have a command line like this
java -classpath yourpackage.YourApp
Just add the property like this
java -Dcom.amd.aparapi.enableShowGeneratedOpenCL=true -classpath yourpackage.YourApp
i exported my java programm to an executable JAR-File.
When i now run this JAR-File:
java -jar myFile.jar
this Exception appears:
Exception in thread "main" java.lang.NullPointerException
at javax.swing.JList$4.getSize(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source)
....
Never saw this before and havent found a solution yet.
What is actually happening here and how can i solve this problem?
It doesn't seems to be a packaging related issue. It looks more like there is a JList not properly initialized - e.g. like if you passed null as the array in the constructor. So check your code...
Procedure:
Expand the jar in exactly the same location as the jar as a directory, say, ExpDir.
Run the main class using -cp ExpDir and main class. Use the same current directory, JVM, and everything else.
If the program now works (1% probability, in my experience), comment on this on the question. Also, confirm that you are not inadvertently changing something else.
If it does not (99% probability), correct the programming error and/or ask a different question appropriate to the error.
I am running my java program but on executing it gives me following error.
before it was running fine but now it's throwing following error.
I checked my class path, path in environment variable all are correct.
Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
at java.util.jar.JarFile.<init>(JarFile.java:135)
at java.util.jar.JarFile.<init>(JarFile.java:72)
at sun.misc.URLClassPath$JarLoader.getJarFile(URLClassPath.java:646)
at sun.misc.URLClassPath$JarLoader.access$600(URLClassPath.java:540)
at sun.misc.URLClassPath$JarLoader$1.run(URLClassPath.java:607)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath$JarLoader.ensureOpen(URLClassPath.java:599)
at sun.misc.URLClassPath$JarLoader.<init>(URLClassPath.java:583)
at sun.misc.URLClassPath$3.run(URLClassPath.java:333)
at java.security.AccessController.doPrivileged(Native Method)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:322)
at sun.misc.URLClassPath.getLoader(URLClassPath.java:299)
at sun.misc.URLClassPath.getResource(URLClassPath.java:168)
at java.net.URLClassLoader$1.run(URLClassLoader.java:194)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: com.sun.tools.javac.Main. Program will exit.
To elaborate on #Peter Lawrey's answer ...
The start of the stacktrace is this:
Exception in thread "main" java.lang.UnsatisfiedLinkError: java.util.zip.ZipFile
.open(Ljava/lang/String;IJ)J
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(ZipFile.java:114)
...
The UnsatisfiedLinkError is thrown when you attempt to call a native method that has not been resolved to a method in the corresponding native library. The rest of the message tells us that the method at fault has the signature:
long java.util.zip.ZipFile.open(String, int, long)
and that meshes with the top frame of the stack trace ... and the fact that Java's ZipFile code is known to use a native library for the heavy lifting.
The fact that it has gotten this far means that the JVM has found the native library and loaded it. But apparently, the load didn't resolve this overload of the native open method. That can only mean one thing: that the version of the ZipFile class on the bootclasspath does not match the native library.
We cannot make any definite conclusions about whether this is a JDK or a JRE, but it seems likely that it is a JDK ... unless the OP is trying to call the Java compiler in a strange way. (The "could not find the main class: com.sun.tools.javac.Main" message probably means that the JVM could not load the class ... because of the UnsatisfiedLinkError breakage.)
Either way, JDK versus JRE is not the immediate problem. The real problem is a mismatch between the "rt.jar" on the JVM's bootclasspath, and the native libraries.
The question asks:
how to solve this then?
It depends on what exactly you did to get this error.
What command did you run?
What were the command line options and arguments?
Have you been "messing around" with your JRE / JDK installation?
Are you trying to use the "rt.jar" file from one installation in another one?
It means your rt.jar is for a different version of Java as your JVM.
I would ensure that you don't have a rt.jar in your boot class path and your JRE is installed correctly.
Could not find the main class: com.sun.tools.javac.Main. Program will exit.
When a class fails to load due to some low level error, it reports that the class could not be found.
The reference in the error message about not finding com.sun.tools.javac.Main leads me to believe that this is a program that needs to be run with the JDK rather than just a JRE.
your JRE path is pointing to the JDK path
Solution :
Step 1: Right click the server
Step 2: Click the Run Time Configuration
Step 3: GIVE the JRE path under the JDK.
Solution fixed
this example of code generates an exception :
Exception in thread "main" java.lang.UnsatisfiedLinkError: no swt-win32-3235 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:134)
at org.eclipse.swt.internal.win32.OS.<clinit>(OS.java:18)
at org.eclipse.swt.widgets.Display.<clinit>(Display.java:125)
at Snippet262.main(Snippet262.java:34)
What does it mean please and how can I resolve it ?
Thank you
You need to add swt-win32-3235.dll to the library_path in your app. By default library_path equals to working dir (".") of your app. Or you may specify path to library_path in vm argument -Djava.library.path=path
So,
1.Check existing swt-win32-3235.dll in your library_path.
2. Check correct definition of library_path property.
This is a runtime exception, that means that the code uses shared library's (using jni probably) which it cannot load.
here you have two options:
the shared library is not installed on you system.
the path to the shared lib is not included in the LD_LIBRARY_PATH (on linux, not sure how it called on windows)
I got the error while running my application. The exception was
java.lang.UnsatisfiedLinkError exception :
SK.gnome.twain.TwainManager.initialize(I[B[BZ)V
I fix it in eclipse as below step, Windows>Preferences>Java>Install JREs>check jre6-32 (check the appropriate versions of jre that you have install in your system).
I'm using the JDK 3.1. I am using XML Publisher. I'm getting this error:
Could not find the main class. Program will exit.
After I click on "OK", I get
Java execution failed. Please check the Java Option in the option dialog
Sounds like you're trying to execute .jar file and there's no Main-Class entry in the manifest file. Other than that obvious point, your question does not give much information for assistance.
Your question is tricky to understand, but I'm guessing that you haven't actually compiled your Java code, or your compiled code isn't on the classpath.
When I try and execute a non-existent class (this would work if there was a MyClass.class on the classpath with a main() method):
paul#paul-laptop:~$ java MyClass
Exception in thread "main" java.lang.NoClassDefFoundError: MyClass
Caused by: java.lang.ClassNotFoundException: MyClass
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: MyClass. Program will exit.
Is that what you're seeing? If so:
compile your class with javac if you haven't done so
check that your classpath includes the location of the class
(You can specify the classpath explicitly when you execute the java program using -classpath, check the documentation for details.)
I include this answer as someone who has made an error someone consuming java rather than programming in it would make:
On the command line when executing a JAR file, be sure your line reads
java -jar whatever.jar
instead of
java whatever.jar
Without the -jar you sometimes get the "Could not find the main class" error.
Here are some good answers What does "Could not find or load main class" mean?
But, I will share one possibility I had. I used the JDK1.7 to compile my code and run the jar package using the JDK1.6, the error is:
Could not find the main class. Program will exit.
So, check if the JDK version you used to run your code is lower than that used to compile your code.
Check this website: "Could not find main class" error when previewing BI Publisher for Word. It directly references Java issues with Oracle BI Publisher Plugins for Word.
It basically says that you need to set your Java Home by going to Options in the BI Publisher Tab in the MS Office Ribbon.