Android Studio “ Attempt To Invoke Virtual Method Android.database.cursor On A Null Object Reference” Problem
I built a gridview with SQLite database, and used cursor to uptade Imageview. It worked well in my last project, but when I combine it with customized toolbar,error shows up java
Solution 1:
Your AddNewMedicine.sqLiteHelper
is null
& that's why you're getting NullPointerException
(Because your AddNewMedicine is already destroyed).
You should create new instance of SqLiteHelper
in MainActivity
instead.
So replace
Cursorcursor= AddNewMedicine.sqLiteHelper.getData("SELECT * FROM MEDICINE");
to
SQLiteHelpersqLiteHelper=newSQLiteHelper(this, "MedicineDB.sqlite", null, 1);
Cursorcursor= sqLiteHelper.getData("SELECT * FROM MEDICINE");
Post a Comment for "Android Studio “ Attempt To Invoke Virtual Method Android.database.cursor On A Null Object Reference” Problem"