I have created a method to do rawQuery which returns a List. But it seems it can't be referenced in feedBackAct. Can anyone Help me?
This is my method in DatabaseHelper Class:
public List<userFeedBackModel> getAll(){
List<userFeedBackModel> list = new ArrayList<>();
String doQuery = "SELECT * FROM " FEEDBACKS_TABLE;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(doQuery, null);
if (cursor.moveToFirst()){
do {
//loop through the cursor to create an object for each report
int userId = cursor.getInt(0);
int roll = cursor.getInt(1);
String name = cursor.getString(2);
String tech = cursor.getString(3);
String contact = cursor.getString(4);
String description = cursor.getString(5);
userFeedBackModel userFeedBack = new userFeedBackModel(userId,roll,name,tech,contact,description);
list.add(userFeedBack);
}
while (cursor.moveToNext());
}
else {
//do nothing
}
cursor.close();
db.close();
return list;
}
this is the code where I am trying to access the getAll()
method but it says Can't resolve this method
btnViewList.setOnClickListener(v ->{
DatabaseHelper databaseHelper = new DatabaseHelper(feedBackAct.this);
List<userFeedBackModel> viewAll = new databaseHelper.getAll();
Toast.makeText(feedBackAct.this, viewAll.toString(), toastLength).show();
});
CodePudding user response:
The problem is in this line
List<userFeedBackModel> viewAll = new databaseHelper.getAll();
Just delete the new and you good to go
List<userFeedBackModel> viewAll = databaseHelper.getAll();