Skip to content

"collection" is null #769

Closed
Closed

Description

@maurxce

I have a Database class which consists of the following code:

package me.lewd.poke.database;


import me.lewd.poke.Main;
import org.dizitart.no2.Nitrite;
import org.dizitart.no2.NitriteCollection;

public class Database {

    public Nitrite db;
    public NitriteCollection pokes;
    private String dataFolder = Main.instance.getDataFolder().getAbsolutePath();

    public void startDatabase() {
        db = Nitrite.builder()
                .filePath(dataFolder + "/data/pokes.db")
                .openOrCreate();

        pokes = db.getCollection("pokes");
    }

    public Nitrite getDatabase() { return db; }
    public NitriteCollection getCollection() { return pokes; }

    public void closeDatabase() {
        if (db.hasUnsavedChanges()) db.commit();
        if (!db.isClosed()) db.close();
    }
}

The startDatabase() method is called on start.
whenever I use the getCollection() method I get this error

java.lang.NullPointerException: Cannot invoke "org.dizitart.no2.NitriteCollection.find(org.dizitart.no2.Filter)" because "collection" is null

Using nitrite 3.4.4

Activity

  1. anidotnet commented on Oct 17, 2022

    @anidotnet
    Contributor

    Which version of JDK are you using? And please paste full stacktrace here.

  2. locked and limited conversation to collaborators on Oct 17, 2022
  3. converted this issue into a discussion #770 on Oct 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions