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=}]}