I'm a new JCuda user and I started to try some samples in my node.
I'm running a simple:
import jcuda.*;
import jcuda.runtime.*;
public class JCudaRuntimeTest{
public static void main(String args[]){
Pointer pointer = new Pointer();
JCuda.cudaMalloc(pointer, 4);
System.out.println("Pointer: "+pointer);
JCuda.cudaFree(pointer);
}
}
I put every library in the same folder and a can easily compile the code, but when I run java JCudaRuntimeTest, I got this exception.
Exception in thread "main" java.lang.NoClassDefFoundError: jcuda/Pointer
at JCudaRuntimeTest.main(JCudaRuntimeTest.java:7)
Caused by: java.lang.ClassNotFoundException: jcuda.Pointer
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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)
... 1 more
suggestions?
NoClassDefFoundError almost always means that something is missing from your classpath.
Make sure the jcuda-<version>.jar file (as well as possibly other necessary JAR files) are on the classpath when you run your program.
You can specify the classpath when you run your program with the -cp switch, for example:
java -cp C:\Project\jcuda\jcuda-0.3.2a.jar;C:\Project\mystuff\classes org.mystuff.MyProgram
or by setting the CLASSPATH environment variable (not recommended).
Related
I seem to be unable to compile a simple MongoDB + Java Example:
I have this file
https://github.com/mongodb/mongo-java-driver/blob/master/examples/QuickTour.java
In my command line I compile by doing
$ javac -cp mongo-2.10.1.jar QuickTour.java
$ java -cp mongo-2.10.1.jar QuickTour
However it gives me the error
Exception in thread "main" java.lang.NoClassDefFoundError: QuickTour
Caused by: java.lang.ClassNotFoundException: QuickTour
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
What is going on and how can I fix this? Is it something to do with my compilation arguments?
Thanks...
It's not the compile time error. It's the error you got when you try to run your class. And the error simply says that it cannot find the class that you are trying to run. That error almost always means that you messed up with the classpath.
The problem is, you forgot to include the current directory in your argument to classpath. Add a dot(.) in addition to your mongo.jar file as the argument to -cp:
java -cp .;mongo-2.10.1.jar QuickTour
This assuming that you are executing your QuickTour class from the same directory where you have placed it.
I have a clock program as AbstractClock.java in C:\Users\Neeraj\Prg folder.
CLASSPATH is specified as C:\Users\Neeraj\Prg
COMPILED javac AbstractClock.java with no errors.
RUN AS java -cp . net.sf.fmj.ejmf.toolkit.media.AbstractClock
Getting errors as
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/fmj/ejmf/toolkit/media/AbstractClock
Caused by: java.lang.ClassNotFoundException: net/sf/fmj/ejmf/toolkit/media/AbstractClock
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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:315)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: com.hib.TranslateSQL. Program will exit.
PROGRAM:-
package net.sf.fmj.ejmf.toolkit.media;
import java.lang.*;
import javax.media.Clock;
import javax.media.Time;
import javax.media.TimeBase;
public class AbstractClock implements Clock {
private TimeBase systemtimebase = Manager.getSystemTimeBase();
public AbstractClock() { super(); }
///REST ALL METHODS
}
I am running this in commandprompt in Windows. I have seen other posts and changed classpath and run command, but still error occurs.Please provide steps suitable for running in windows in command prompt to rectify this mistake.
Is you java file in C:\Users\Neeraj\Prg or is it in C:\Users\Neeraj\Prg\net\sf\fmj\ejmf\toolkit\media\ ?
Packages in java are related to directories. So your classpath is the top level directory in which packages live. A class with the package name net.sf.fmj.ejmf.toolkit should be in that directory.
So I have such class:
public class Main {
public static void main(String[] args) {}
}
I work on Windows 7 and I've changed current locale to English (USA).
When I run this class on path such C:\Москва I have error message:
Exception in thread "main" java.lang.NoClassDefFoundError: Main
Caused by: java.lang.ClassNotFoundException: Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: Main. Program will exit.
When I run this class on path such C:\Moscow I have no errors and it works.
If my locale Russian everything is OK.
Please help me to understand. Why this happens.
C:\Москва is this folder in CLASSPATH? I suspect it is not. NoClassDefFoundError happens if a class was not available in java classpath during runtime. Add that folder to classpath. Here is good link on why this happens and what you need to do. NoclassDefFoundError
I'm starting to become pretty irritated, because EVERY time I try to add a JAR file to the classpath to run a program (which compiles fine in Eclipse) I get a "java.lang.NoClassDefFoundError" exception.
The file swt.jar and GUI.class (main class) are in the same directory. If I issue this command: "java -cp swt.jar GUI", I get this error message:
Exception in thread "main" java.lang.NoClassDefFoundError: GUI Caused
by: java.lang.ClassNotFoundException: GUI at
java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247)
If I formulate the command like this: "java GUI -cp swt.jar", it'll throw this exception:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/eclipse/swt/widgets/Display at GUI.main(GUI.java:9) Caused by:
java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Display at
java.net.URLClassLoader$1.run(URLClassLoader.java:202) at
java.security.AccessController.doPrivileged(Native Method) at
java.net.URLClassLoader.findClass(URLClassLoader.java:190) at
java.lang.ClassLoader.loadClass(ClassLoader.java:306) at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at
java.lang.ClassLoader.loadClass(ClassLoader.java:247) ... 1 more
I just want to know how I can add .jar files to the runtime classpath on mac.
All of these commands are being issued from the Terminal on a 64-bit MacBook running Mac OS X Lion.
The problem, I think, is that you are specifying swt.jar as the classpath, but the file you're using is not in the jar. You neeed to specify both the jar and this dir as the classpath.
e.g.
java -cp swt.jar:./ GUI
This one will work, with modifications:
If I formulate the command like this: "java GUI -cp swt.jar"
You just didn't go far enough. You have to add ALL the 3rd party JARs, including the ones for Eclipse SWT and all your other dependencies.
import java.io.*;
public class ArrayApp{
public static void main(String[] args){
System.out.println("lllll");
} // end main()
} // end class ArrayApp
i get this error when i run my application after compiling it.
Exception in thread "main" java.lang.NoClassDefFoundError: ArrayApp
Caused by: java.lang.ClassNotFoundException: ArrayApp
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
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: ArrayApp. Program will exit.
You need to make sure your class file is in the classpath. Assuming you are using the default package (i.e. no package declaration), you need to tell Java where to find your class when you run it. So let's assume your ArrayApp.class file is in the same directory. You will need to run it like this:
java -cp . ArrayApp
The option -cp and the following . tell Java that the classes will be in the current directory. The longer name for -cp is -classpath, so you can use that as well.
Also note the space between the classpath and the class name. The path is the base directory of where your class files are located. If you compiled them into a directory named "bin" then you would change the way you call Java like this:
java -cp bin/ ArrayApp
The "ArrayApp" is the fully qualified class name.
Your classpath is incorrect. Try...java -classpath . ArrayApp