Search code examples
javaandroidobjectreferencetinydb

TinyDB error putint null object reference android


TinyDb class is here

im using it simply by default codes like : TinyDB tinyDB = new TinyDB(MyActivity.this); and tinyDB.putInt("hadi" , 10);

but im getting an error that i cant understand . it say tinyDB is null object reference . you can see the error below :

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.example.ahmadi.TinyDB.TinyDB.putInt(java.lang.String, int)' on a null object reference

Solution

  • You have to create Object of Your TinyDB class like :-

    TinyDB tinyDB = new TinyDB();