本文介绍了线程“main"中的异常java.lang.NoClassDefFoundError: org/sqlite/NativeDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 mac 上为 sqlite 运行一个简单的示例.我很确定代码在 Windows 上运行良好.但不是在 mac 上.如果有人能帮我解决这个问题,我真的很感激.

I am trying run an simple example for sqlite on mac. I am pretty sure the code works well on Windows. But not on mac. I really appreciate it if someone could help me with this.

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

The code is running in Eclipse. I added the sqlite-jdbc4-3.8.2-SNAPSHOT.jar as internal & external jar in the project.

  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',0,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.

Finally I figured out how to make it work. I tried another jar and it(sqlite-jdbc-3.7.2.jar) works well for Mac. It seems that sqlite-jdbc4-3.8.2-SNAPSHOT.jar. @ddevienne , maybe 3.8.2 does not support Mac OS.

这篇关于线程“main"中的异常java.lang.NoClassDefFoundError: org/sqlite/NativeDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:10