2012-06-20 14 views
0

Hey je suis un plus récent à anrdoid.Près j'ai eu un problème dans db4o. quand j'utiliseDb4oClientServer ne peut pas ouvrir le serveur

public static void main(String[] args) { 

      ServerConfiguration configuration= 
       Db4oClientServer.newServerConfiguration(); 
     configuration.common().allowVersionUpdates(true); 
      configuration.common().activationDepth(4); 
     try{ 


     server=Db4oClientServer.openServer(
       configuration,"test",0); 
     System.out.println("It's ok"); 

     }catch(Exception e){ 
      System.out.println(e.toString()); 
     } 
    } 

un simple java file.It fonctionne bien. (Je n'ai pas le fichier nommé « test »). Et il me permet de créer le fichier de test .Mais quand j'utilise la même code dans un projet Android.

private ServerDDBB(){ 
    try{ 
     if(QSLog.DEBUG_I) 
      QSLog.i(CLASS_NAME,"Before to open the DDBB"); 

     ServerConfiguration configuration= 
      Db4oClientServer.newServerConfiguration(); 
    configuration.common().allowVersionUpdates(true); 
     configuration.common().activationDepth(DEEP); 
    try{ 
    server=Db4oClientServer.openServer(
      configuration,"ddbb",0); 
    }catch(Exception e){ 
     Log.e("Can't pass the openServer",e.toString()); 
    } 
     if(server==null) 
      if(QSLog.DEBUG_W) 
       QSLog.w(CLASS_NAME, "Serer Null"); 

    }catch(Exception e){ 
     if (QSLog.DEBUG_E)QSLog.e("hey", ExceptionUtils.exceptionTraceToString(
       e.toString(), 
       e.getStackTrace())); 
    } 
} 

Il me invite il y a une exception IO.

C'est mon avertissement d'erreur:. Com.db4o.io.RandomAccessFileFactory.newRandomAccessFile (RandomAccessFileFactory.java:26) com.db4o.io.FileStorage $ FileBin (FileStorage.java:43) com.db4o.io. FileStorage.open (FileStorage.java:22) com.db4o.io.StorageDecorator.open (StorageDecorator.java:27) com.db4o.io.CachingStorage.open (CachingStorage.java:52) com.db4o.internal.IoAdaptedObjectContainer. openImpl (IoAdaptedObjectContainer.java:56) com.db4o.internal.ObjectContainerBase $ 1.run (ObjectContainerBase.java:134) com.db4o.foundation.DynamicVariable.with (DynamicVariable.java:47) com.db4o.foundation.Environments.runWith (Environments.java:28) com.db4o.internal.ObjectContainerBase.withEnvironment (ObjectContainerBase.java:155) com.db4o.internal.ObjectContainerBase.open (ObjectContainerBase.java:125) com.db4o.internal.IoAdaptedObjectContainer . (IoAdaptedObjectContainer.java:35) com.db4o.internal.ObjectContainerFactory.openObjectContainer (ObjectContainerFactory.java:18) com.db4o.Db4o.openFile (Db4o.java:224) com.db4o.cs.internal.config.StandardClientServerFactory. openServer (StandardClientServerFactory.java:35) com.db4o.cs.Db4oClientServer.openServer (Db4oClientServer.java:52) com.hlh.ddbb.ServerDDBB. (ServerDDBB.java:37) com.hlh.ddbb.ServerDDBB.createInstance (ServerDDBB .java: 84) com.hlh.ddbb.ServerDDBB.getServer (ServerDDBB.java:78) com.hlh.ddbb.ClientDDBB. (ClientDDBB.java:20) com.hlh.SettingsTab.initActivity (SettingsTab.java:196) com.hlh.SettingsTab.onCreate (SettingsTab.java:91) android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1047) android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2459) android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2512) android.app.ActivityThread.access $ 2200 (ActivityThread.java:119) android.app.ActivityThread $ H.handleMessage (ActivityThread.java:186 3) android.os.Handler.dispatchMessage (Handler.java:99) android.os.Looper.loop (Looper.java:123) android.app.ActivityThread.main (ActivityThread.java:4363) java.lang.reflect. Method.invokeNative (Méthode native) java.lang.reflect.Method.invoke (Method.java:521) com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:860) com.android.internal.os .ZygoteInit.main (ZygoteInit.java:618) dalvik.system.NativeStart.main (méthode native)

Toute réponse sera agréable.

Répondre

0

On dirait que vous essayez simplement d'utiliser un nom de fichier normal. Dans Android, vous devez stocker la base de données dans un location, où vous avez accès à:

String filePath = this.getFilesDir() + "/android.db4o"; 
    final EmbeddedConfiguration config = Db4oEmbedded.newConfiguration(); 
    config.common().add(new AndroidSupport()); 
    ObjectContainer db = Db4oEmbedded.openFile(config,filePath); 

btw. Vous n'avez pas besoin du fichier jar du serveur client intégré. Vous pouvez ouvrir un nouveau conteneur de session avec le standard container:

ObjectContainer session = rootContainer.ext().openSession(); 
try { 
    // do the operations on the session-container 
    session.store(new Person("Joe")); 
} finally { 
    // close the container. For example when the request ends 
    session.close(); 
} 
Questions connexes