couchbaselabs / TouchDB-Android

CouchDB-compatible mobile database; Android version

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

create a new db

somentelucas opened this issue · comments

Hello, I'm starting with TouchDB today and I'm having a issue that seems to be very simple, but as I'm new and there is not many documentation yet, I couldn't find a solution.

I just want to create a new empty database based on the tutorial:

HttpClient httpClient = new TouchDBHttpClient(server);
CouchDbInstance dbInstance = new StdCouchDbInstance(httpClient);
dbInstance.createConnector("testedb", true);

but I keep getting this error

05-14 23:13:25.027: ERROR/AndroidRuntime(903): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.couchbase.grocerysync/com.couchbase.grocerysync.AndroidGrocerySyncActivity}: org.ektorp.DbAccessException: com.couchbase.touchdb.ektorp.TouchDBHttpResponse@40df2808
URI: touchdb:///testedb/
Response Body:
null
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.ektorp.DbAccessException: com.couchbase.touchdb.ektorp.TouchDBHttpResponse@40df2808
URI: touchdb:///testedb/
Response Body:
null
at org.ektorp.http.StdResponseHandler.createDbAccessException(StdResponseHandler.java:44)
at org.ektorp.http.StdResponseHandler.error(StdResponseHandler.java:62)
at org.ektorp.http.RestTemplate.handleVoidResponse(RestTemplate.java:98)
at org.ektorp.http.RestTemplate.put(RestTemplate.java:39)
at org.ektorp.impl.StdCouchDbInstance.createDatabase(StdCouchDbInstance.java:51)
at org.ektorp.impl.StdCouchDbInstance.createDatabase(StdCouchDbInstance.java:43)
at org.ektorp.impl.StdCouchDbConnector.createDatabaseIfNotExists(StdCouchDbConnector.java:387)
at org.ektorp.impl.StdCouchDbInstance.createConnector(StdCouchDbInstance.java:103)
at com.couchbase.grocerysync.AndroidGrocerySyncActivity.startTouchDB(AndroidGrocerySyncActivity.java:126)
at com.couchbase.grocerysync.AndroidGrocerySyncActivity.onCreate(AndroidGrocerySyncActivity.java:83)
at android.app.Activity.performCreate(Activity.java:5104)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
... 11 more

Thanks,

Lucas

Heres the code I use to make a db and it works.

server = new TDServer(filesDir);
httpClient = new TouchDBHttpClient(server);  
dbInstance = new StdCouchDbInstance(httpClient);
dbConnector = dbInstance.createConnector(localDB, false);
dbConnector.createDatabaseIfNotExists();

So the code is fine. (the true does the next line explicitly). From the error it throws, createDbAccessException, I'm guessing you don't have write permissions on the directory you instantiated TDServer with or something similar? What path are you passing to the TDServer constructor?

I manage to solve it, apparently there was another error that I hadn't seen and what I had to do was to copy the libcom_couchbase_touchdb_TDCollateJSON.so libs into the project and it worked fine.

Thanks anyway!