我有一个从Couchbase Server同步的沙发基准数据库。但是当我尝试创建视图然后查询时,出现异常
getViewID()
代码是,日志如下:
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)
最佳答案
我不在Java版本的CBL上工作,所以我不知道特定异常的含义。但是,您的代码有一个错误:您仅在首次创建视图时才设置视图的地图功能(Mapper
)。这是不正确的。视图是持久性的,但map函数(因为它实际上只是一个任意函数)不是持久性的。这意味着,在您第一次查询视图之前,每次您运行该应用程序时都必须注册地图功能。
关于android - 在Android应用程序中获取异常“getViewID()<0,状态:404(HTTP 404 not_found)”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37653325/