线程“main”中的异常java.lang.NoClassDefFoundError:org/sqlite/NativeDB

前端之家收集整理的这篇文章主要介绍了线程“main”中的异常java.lang.NoClassDefFoundError:org/sqlite/NativeDB前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试在mac上运行一个简单的sqlite示例.我很确定该代码Windows上运行良好.但不是在Mac上.如果有人能帮助我,我真的很感激.

代码Eclipse中运行.我添加sqlite-jdbc4-3.8.2-SNAPSHOT.jar作为内部和&项目中的外部jar.

public class Test1 {

  private static Connection c;
  private static String filepath = "/Users/zerocraft/Documents/workspace/sql_test/";
  private static String sql;
  private static Statement query;


  public static void main(String[] args) {
          System.out.println("START");
          try{

            Class.forName("org.sqlite.JDBC");
            System.out.println("START2");

            c = DriverManager.getConnection("jdbc:sqlite:"+filepath+"projone.db");
            System.out.println("START3");

            }

            catch(Exception e){
                e.printStackTrace();
            }

                 sql =  "INSERT INTO table(date,time,client_id,run_id,latitude," +
                        "longitude,bearing,speed,altitude,sensor_id,sensor_type," +
                        "sensor_value,attribute)"
                + "VALUES ('A','B','C','D',1,2,3,4,'E','F','G','H')";


                try{
                query = c.createStatement();

                 query.executeUpdate(sql);
                 query.close();
                }
                catch(sqlException el){el.printStackTrace();}
        }   
   }

安慰 ##

START
  START2
  Exception in thread "main" java.lang.NoClassDefFoundError: org/sqlite/NativeDB
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
at java.lang.Runtime.load0(Runtime.java:795)
at java.lang.System.load(System.java:1062)
at org.sqlite.sqliteJDBCLoader.loadNativeLibrary(sqliteJDBCLoader.java:200)
at org.sqlite.sqliteJDBCLoader.extractAndLoadLibraryFile(sqliteJDBCLoader.java:148)
at org.sqlite.sqliteJDBCLoader.loadsqliteNativeLibrary(sqliteJDBCLoader.java:249)
at org.sqlite.sqliteJDBCLoader.initialize(sqliteJDBCLoader.java:65)
at org.sqlite.core.NativeDB.load(NativeDB.java:53)
at org.sqlite.core.CoreConnection.open(CoreConnection.java:136)
at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:66)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:21)
at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:23)
at org.sqlite.sqliteConnection.<init>(sqliteConnection.java:44)
at org.sqlite.JDBC.createConnection(JDBC.java:113)
at org.sqlite.JDBC.connect(JDBC.java:87)
at java.sql.DriverManager.getConnection(DriverManager.java:571)
at java.sql.DriverManager.getConnection(DriverManager.java:233)
at sql_test.Test1.main(Test1.java:22)
   Caused by: java.lang.ClassNotFoundException: org.sqlite.NativeDB
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 21 more

解决方法

最后,我想出了如何让它发挥作用.我尝试了另一个jar,它(sqlite-jdbc-3.7.2.jar)适用于Mac.看来是sqlite-jdbc4-3.8.2-SNAPSHOT.jar. @ddevienne,也许3.8.2不支持Mac OS.

猜你在找的Java相关文章