I have a two tables that are Subject and chapter. I need to display chapter_name by passing
Subject_id. My question is that how to do that? When I pass value id doesn’t return anything.
Please give some hint.
Here is my code for reference.
public List<ObjectiveWiseQuestion> getAllChapter(long subId)
{
List<ObjectiveWiseQuestion>LocwiseProfileList=new ArrayList<ObjectiveWiseQuestion>();
String selectQuery=("select chapterName from chapter where subject_id ='"+ subId +"'");
db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst())
{
do {
ObjectiveWiseQuestion owq= new ObjectiveWiseQuestion();
owq.setChapterName(cursor.getString(2));
LocwiseProfileList.add(owq);
} while(cursor.moveToNext());
db.close();
}
return LocwiseProfileList;
}
It also shows illegalState Exception.
change:
to this:
and dont forget to close your cursor too right before closing database: