I created following method in SQLiteOpenHelper subclass:
public List<Data> getAll(){
List<Data> returnList = new ArrayList<>();
String queryString = "SELECT * FROM " + table;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(queryString, null);
if(cursor.moveToFirst()){
do {
int ID = cursor.getInt(0);
int soundamp = cursor.getInt(1);
String date = cursor.getString(2);
String time = cursor.getString(3);
double lat = cursor.getDouble(4);
double lon = cursor.getDouble(5);
Data newData = new Data(ID, soundamp, date, time, lat, lon);
returnList.add(newData);
}while(cursor.moveToNext());
}
cursor.close();
db.close();
return returnList;
}
But when I try to use this method in MainActivity on button click like this:
else if(v==viewAll){
SQLite sql = new SQLite(MainActivity.this);
List<Data> all = new sql.getAll();
}
"getAll" gets highlighted red and I get the following message when I hover over it: Cannot resolve symbol 'getAll'. Now I have tried Invalidating caches and restarting project but it didn't work, I have also tried Importing to a new project but that didn't work either.