开发者

Cannot load an SQLite JDBC Driver, Any Ideas?

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.l开发者_如何学JAVAoadClass(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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜