Db4o DataConnection错误

时间:2012-11-19 21:47:44

标签: java db4o

我想使用db4o,我在youtube.com教程中学习这个。不幸的是我无法在我的代码中找到错误。我想知道为什么我有错误?我添加了所有重要的库。

enter image description here

代码重要类:

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

1 个答案:

答案 0 :(得分:1)

尝试替换

new DataConnection.getInstance()

DataConnection.getInstance()

关键字new仅在创建新对象时使用。在这里,您将调用静态方法。