I am using DB browser for SQLite to create an external database, the file name's words_library.db inside that file I have a table called dictionary.db that contains 3 columns : "English_lib", "German_lib", "_id" as shown below (Fig. 1)
What I am trying to do is populating a recyclerview with that database but I failed to do so.
JAVA
public void fetchData() //this method is called to populate the RecyclerView
{
db =new DataBaseHelper(getContext());
try {
db.createDataBase();
db.openDataBase();
}
catch (Exception e)
{
e.printStackTrace();
}
namelist=new LinkedHashMap<>();
int ii;
SQLiteDatabase sd = db.getReadableDatabase();
Cursor cursor = sd.query("dictionary_lib" ,null, null, null, null, null, null);
ii=cursor.getColumnIndex("_id");
eng_list=new ArrayList<String>();
ger_list= new ArrayList<String>();
id_list= new ArrayList<String>();
cursor.moveToFirst();
while (cursor.moveToNext()){
namelist.put(cursor.getString(ii), cursor.getString(cursor.getColumnIndex("English_lib")));
}
Iterator entries = namelist.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry thisEntry = (Map.Entry) entries.next();
id_list.add(String.valueOf(thisEntry.getKey()));
eng_list.add(String.valueOf(thisEntry.getValue()));
ger_list.add(String.valueOf(thisEntry.getValue()));
}
for (int i = 0; i < eng_list.size(); i++) {
data.add(new DictObjectModel(eng_list.get(i), ger_list.get(i)));
}
adapter = new CustomAdapter(data);
rv.setAdapter(adapter);
}
LOG
Failed to read row 1, column -1 from a CursorWindow which has 3469 rows, 2 columns.
java.lang.IllegalStateException: Couldn't read row 1, col -1 from CursorWindow.
Make sure the Cursor is initialized correctly before accessing data from it.
fig 1 :
an example of the database I have and the recyclerview should only have the English_lib and the German_lib columns shown

Cursor cursor = sd.rawQuery("SELECT * FROM dictionary_lib", null);and see what happens.namelist.put(cursor.getString(ii), cursor.getString(cursor.getColumnIndex("English_lib")));