Android Couchbase queryViewNamed on a null object reference

Hello I have a big problem. I have implemented logout functionality to my app. When user logouts I delete database and all the replications and then immediately create new database
//delete database
@Override
public void deleteDatabase() {
try {
database.removeChangeListener(this);
manager.close();

            noteCreatedView.delete();
            notesView.delete();
            poiView.delete();
            sessionsView.delete();

            database.delete();
            database = null;
        } catch (CouchbaseLiteException e) {
            e.printStackTrace();
        }
    }

//create database

 @Override
    public void createDatabase(Context context) {
        this.context = context;
        try {
            manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS);
            database = manager.getDatabase(COUCHBASE_DB_NAME);
            database.addChangeListener(this);

            noteCreatedView = database.getView(DocNote.KEY_CREATED);
            notesView = database.getView(DocNote.TYPE);
            poiView = database.getView(DocPoi.TYPE);
            sessionsView = database.getView(DocSession.TYPE);

            setCreatedIndexMap();
            setTypeIndex();
            setPoiIndex();
            setSessionsIndex();

            boolean isSimulationDeleted = database.getDocument(DEMO_TRIP_DOC_ID) == null;

couchbaseAnalytics = new CouchbaseAnalyticsImpl(notesView, sessionsView, isSimulationDeleted);
} catch (IOException | CouchbaseLiteException e) {
e.printStackTrace();
Crashlytics.logException(e);
}
}

ant then after user login I immediately call this method

@Override
    public int getNotesCount() {
        ThreadUtils.assertIsWorkerThread();
        Query query = notesView.createQuery();
        try {
            QueryEnumerator result = query.run();
            return result.getCount();
        } catch (CouchbaseLiteException e) {
            e.printStackTrace();
        }
        return 0;
    }

and here QueryEnumerator result = query.run(); I got this crash. Any ideas what I may be doing wrong?

Hi @deividas.aukstakalni,

What kind of crash did you get? Is there an error message?

Please specify the version of Couchbase Lite and Sync Gateway that you are using. And please include the stack trace.