SQLite query execution crashes Android App
I am populating a listview from SQLite database, and the app crashes when
I click on an item. I have done enough research using "query" and
"rawquery". Also successfully executed rawquery statement in SQLite
Database Browser, but still the same statement doesn't work in my code.
Below is the code of my listview onitemclicklistener:
// Bookmark ListView Listener
bookmarkListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent1, View view1, int
position1,
long id1) {
String selectedBookmarkItem =
((TextView)view1).getText().toString();
dbAdapter.read();
Map<String, Object> bookmarkKV =
dbAdapter.getSingleBookmark(selectedBookmarkItem);
String bookmarkedURL = (String)
bookmarkKV.get(dbAdapter.BOOKMARK_ADDRESS);
dbAdapter.close();
Toast.makeText(getBaseContext(), bookmarkedURL,
Toast.LENGTH_LONG).show();
}
});
Method getSingleBookmark code:
// Fetch Single Bookmark
public Map<String, Object> getSingleBookmark(String bookmarkName1) throws
SQLException{
Map<String, Object> map1 = new HashMap<String, Object>();
Cursor cursor1 = db.query(true, BOOKMARKS_TABLE, new String[]
{BOOKMARK_ADDRESS},
BOOKMARK_NAME + "=" + bookmarkName1, null, null, null, null,
null);
if(cursor1 != null){
cursor1.moveToFirst();
}
String bookmarkAddress =
cursor1.getString(cursor1.getColumnIndex(BOOKMARK_ADDRESS));
map1.put(BOOKMARK_ADDRESS, bookmarkAddress);
//String bookmarkName =
cursor1.getString(cursor1.getColumnIndex(BOOKMARK_NAME));
//map1.put(BOOKMARK_NAME, bookmarkName);
return map1;
}
LogCat entry:
09-30 03:43:12.791: E/AndroidRuntime(29008): FATAL EXCEPTION: main
09-30 03:43:12.791: E/AndroidRuntime(29008):
android.database.sqlite.SQLiteException:
no such column: gmail (code 1): , while compiling: SELECT DISTINCT
bookmarkaddress
FROM bookmarkstable WHERE bookmarkname=gmail
When I click on "gmail" item in listview, the app crashes saying
"Unfortunately, App has stopped".
But the database table has the row with "gmail" entry:
No comments:
Post a Comment