Question

I would like to use db4o and I`m learning this using in youtube.com tutorial. Unfortunately I'm not able to find mistake in my code. I would like to know why I have got there error? I added all important library.

enter image description here

Code important class:

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();
    }
}
}

Here is this tutorial (important thing 5:44): http://www.youtube.com/watch?v=dcNfkED53to

Was it helpful?

Solution

Try replacing

new DataConnection.getInstance()

with

DataConnection.getInstance()

The keyword new is only used when creating a new object. Here you are calling a static method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top