androidcouchbasecouchbase-litecouchbase-view

Getting an exception "getViewID() < 0, Status: 404 (HTTP 404 not_found)" in android application


I have a couchbase lite database synced from the Couchbase Server. But when i try to create a view and then query it I get an exception

getViewID() < 0, Status: 404 (HTTP 404 not_found).

The code is and logs are following:

        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());
        }

Here is the log:

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)

Solution

  • I don't work on the Java version of CBL so I don't know what that specific exception means. However, your code has a mistake: you're only setting the map function (Mapper) of the view when you first create the view. This is incorrect. The view is persistent, but the map function (since it's effectively just an arbitrary function) isn't. That means the map function has to be registered every time you run the app, before the first time you query the view.