我想使用 db4o,我正在 youtube.com 教程中学习这个。不幸的是,我无法在我的代码中找到错误。我想知道为什么我会出现错误?我添加了所有重要的库。
代码重要类:
package data;
import com.db4o.*;
import com.db4o.config.EmbeddedConfiguration;
public class DataConnection {
private static DataConnection INSTANCE =null;
private final String PATH = "test.db4o";
private static ObjectContainer db;
private DataConnection(){}
private synchronized static void createInstance(){
if (INSTANCE ==null){
INSTANCE = new DataConnection();
INSTANCE.performConnection();
}}
public void performConnection() {
EmbeddedConfiguration config = Db4oEmbedded.newConfiguration();
db = Db4oEmbedded.openFile(config, PATH);
}
public static ObjectContainer getInstance() {
if(INSTANCE == null) createInstance();
return db;
}
public static void closeConnection() {
try{
db.close();
}
catch (Exception e) {
e.printStackTrace();
}
}
}
这是本教程(重要的事情 5:44): http ://www.youtube.com/watch?v=dcNfkED53to