tags:

views:

51

answers:

2

I am trying to build a simple java program which creates a db file, then a table and inserts dummy values in the table. I found this page http://www.zentus.com/sqlitejdbc/index.html and tried out the example given on the page but I am getting 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)
Could not find the main class: Test.  Program will exit.
+1  A: 

Well that looks like it's a matter of the classpath not being right.

My guess is that you're

If you've put something like

java -cp sqlitejdbc-v056.jar Test

then you probably just need to add the current directory to the classpath:

# Windows
java -cp sqlitejdbc.jar-v056;. Test

# Unix
java -cp sqlitejdbc.jar-v056:. Test

Having looked at that page, my guess is that you used : as the classpath separator, as shown on the page, rather than ; which you need to use if you're on Windows.

Jon Skeet
@Jon: I had just copied and pasted the : classpath separator. But I tried what you said I am still getting the same error. Have you tried the example. Is it working for you?
Bruce
@Jon: I tried it again. Its working now. Thanks a lot!
Bruce
@Jon: If I create an environment user variable CLASSPATH with value '.' will it work?
Bruce
@Bruce: I can't remember offhand whether specifying both CLASSPATH and -cp will combine the two - I suspect not. I think it's best to just put it on the command line, or use an IDE so you don't need to do it manually all the time.
Jon Skeet
+1  A: 

Are you sure you're building the test correctly? Here are the steps you'll need to take:

  1. Create a file named Test.java, because it will contain the class named Test
  2. Paste the Java code from the Getting Started section into this file and save it
  3. Download the sqlitejdbc-v056.jar file and put it in the same directory as the Test.java file
  4. Use javac to compile Test.java into Test.class
  5. Run the command from the Getting Started section

You should see:

name = Gandhi
job = politics
name = Turing
job = computers
name = Wittgenstein
job = smartypants

as output.

jasonmp85
@jasonmp85: Is the example working on your computer?
Bruce
Indeed it is, hence the output.
jasonmp85