我正在尝试将我的 android 应用程序与本地主机上的 couchbase 服务器连接我已经初始化数据库和管理器如下:初始化数据库后,我正在调用 startSync() 函数接受数据库类型的参数
public static final String DB_NAME = "firstdb";
public static final String TAG = "firstdb";private void helloCBL() {
Manager manager = null;
Database database = null;
try {
manager = new Manager(new AndroidContext(this), Manager.DEFAULT_OPTIONS);
database = manager.getDatabase(DB_NAME);
database.addChangeListener(this);
startSync(database);
} catch (Exception e) {
Log.e(TAG, "Error getting database", e);
return;
}
}
这是 startSync() 函数
protected void startSync(Database database) {
URL syncUrl;
try {
syncUrl = new URL("http://10.0.2.2:4984/firstdb");
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
Replication pullReplication = database.createPullReplication(syncUrl);
pullReplication.setContinuous(true);
Replication pushReplication = database.createPushReplication(syncUrl);
pushReplication.setContinuous(true);
pullReplication.addChangeListener(this);
pushReplication.addChangeListener(this);
// start both replications
pullReplication.start();
pushReplication.start();
}
但是我的 logcat 出现错误如下:我对在 android 应用程序中使用 url 感到困惑
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: io exception. url: http://10.0.2.2:4984/firstdb/_local/2b7e37db76812fef1b8c7ca3d4b30b99e570ea6f
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.2.2:4984 timed out
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:144)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at com.couchbase.lite.support.RemoteRequest.executeRequest(RemoteRequest.java:184)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at com.couchbase.lite.support.RemoteRequest.run(RemoteRequest.java:103)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.FutureTask.run(FutureTask.java:234)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
12-10 02:36:16.930 4556-4588/com.couchbase.examples.couchdbapp E/RemoteRequest: at java.lang.Thread.run(Thread.java:856)
当我在 android 设备上运行应用程序时会发生这些错误。当我在模拟器上运行我的应用程序时,它没有显示任何错误,但会给出详细的消息
12-10 13:13:03.482 3718-3770/com.couchbase.examples.couchdbapp W/Sync: com.couchbase.lite.replicator.PullerInternal@3139637: Received invalid doc ID from _changes: {seq=1, id=_user/, changes=[{rev=}]}