tags:

views:

538

answers:

2

So i need to write a program that accesses and modifies an SQLite DB for a school program and am looking at the basics firstly. Now, I am looking at this to get me started: link text. The problem is that when i compile Test.java (The example code on the website) and then run the command:

java -cp .:sqlitejdbc-v056.jar Test

like it tells me to, i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: Test
Caused by: java.lang.ClassNotFoundException: Test
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Test.  Program will exit.

Test.java, Test.class and sqlitejdbc-v056.jar are all in the same folder so they should find each other. Does anybody have an idea about what i am doing wrong?

+1  A: 

As the exception message is saying, the problem is that it cannot find the class Test. So the problem is not finding SQLite, but finding your Test class.

Just a guess, but I am wondering if there is an issue with how you compiled. In the Test.java, does the class belong to a package? If so, you need to compile it using the -d flag so that it gets put in the appropriate sub-directory.

Rob Di Marco
+1  A: 

According to the java.lang.NoClassDefFoundError: Test, the Test class cannot be found in the CLASSPATH. But you wrote that Test.class is available in the current directory so I'm gonna guess something. Actually, I think that you are not using the right CLASSPATH separator character (which is platform dependent) and thus not building correctly the CLASSPATH. On Windows, you should use ; instead of :. If this happens to be the case, you should try this:

java -cp .;sqlitejdbc-v056.jar Test

If you are on a unix-like platform, forget this answer, the problem is elsewhere.

Pascal Thivent
Good analysis. Classpaths are notoriously tricky.
Thorbjørn Ravn Andersen
Thank you very much that solved my problem, Much appreciated.Was just wondering though, What is the difference between these: java -cp .;sqlitejdbc-v056.jar Test java -cp .;sqlitejdbc-v056.jar Test.classBecause when i put the ".class" at the end, I get errors.Thank you.
ManBeast
Thank you very much that solved my problem, Much appreciated. Was just wondering though, What is the difference between these two commands: "java -cp .;sqlitejdbc-v056.jar Test" and then "java -cp .;sqlitejdbc-v056.jar Test.class" Because when i put the ".class" at the end, I get errors. Thank you
ManBeast
You're welcome. Regarging `java -cp .;sqlitejdbc-v056.jar Test.class`, this is just not how you invoke a class with `java`. The `java` command takes the *Name of the class to be invoked* as argument (Test), not a file (Test.class).
Pascal Thivent