我有一个从Couchbase服务器同步的couchbase lite数据库。但是当我尝试创建一个视图然后查询它时,我得到一个异常
getViewID()< 0,状态:404(HTTP 404 not_found)。
代码是和日志如下:
db = application.getDatabaseInstance();
View membersView = db.getView("membersView");
if (membersView == null) {
membersView.setMap(
new Mapper(){
@Override
public void map(Map<String, Object> document, Emitter emitter) {
Log.e("inside map", "map");
Object fname = document.get("FatherName");
if (fname != null)
emitter.emit((String) document.get("Id"), document);
}
}, "2" /* The version number of the mapper... */
);
}
Query query = membersView.createQuery();
query.setMapOnly(true);
QueryEnumerator result = query.run();
Log.e("here", "here");
for (Iterator<QueryRow> it = result; it.hasNext(); ) {
QueryRow row = it.next();
Log.e("row", (String) row.getValue());
}
这是日志:
06-06 13:52:20.923 6080-6080/com.bops.app.track.reps V/View: Re-indexing view: membersView
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: com.couchbase.lite.CouchbaseLiteException: getViewID() < 0, Status: 404 (HTTP 404 not_found)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.couchbase.lite.store.SQLiteViewStore.updateIndexes(SQLiteViewStore.java:252)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.couchbase.lite.View.updateIndexes(View.java:321)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.couchbase.lite.View.updateIndex(View.java:294)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.couchbase.lite.Database.queryViewNamed(Database.java:2057)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.couchbase.lite.Query.run(Query.java:433)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.bops.app.track.reps.MainActivity.onCreate(MainActivity.java:76)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.Activity.performCreate(Activity.java:6251)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.ActivityThread.-wrap11(ActivityThread.java)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.os.Handler.dispatchMessage(Handler.java:102)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.os.Looper.loop(Looper.java:148)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at java.lang.reflect.Method.invoke(Native Method)
06-06 13:52:20.925 6080-6080/com.bops.app.track.reps W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
06-06 13:52:20.926 6080-6080/com.bops.app.track.reps W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
答案 0 :(得分:1)
我没有使用CBL的Java版本,因此我不知道该特定异常的含义。但是,您的代码有一个错误:您只在第一次创建视图时设置视图的地图功能(sum(np.array([[[2,3,4],[4,5,6]],[[7,8,9],[10,11,12]]]))
Out[47]:
array([[ 9, 11, 13],
[14, 16, 18]])
np.sum(np.array([[[2,3,4],[4,5,6]],[[7,8,9],[10,11,12]]]), axis=0)
Out[48]:
array([[ 9, 11, 13],
[14, 16, 18]])
np.sum(np.array([[[2,3,4],[4,5,6]],[[7,8,9],[10,11,12]]]))
Out[49]: 81
)。这是不正确的。视图是持久的,但是map函数(因为它实际上只是一个任意函数)并不是。这意味着每次运行应用程序时,必须在第一次查询视图之前注册地图功能。