I'm trying to retrieve the data of a particulate row in a sqlite database . and trying to display it to on a EditText but I'm getting this error , Kindly help me in solving the error !
Thanks in advance :)
here is the logcat data showing error
12-31 22:28:17.731: E/2.4(12285): 111111 12-31 22:28:17.741: E/2.5(12285): 111111 12-31 22:28:17.771: E/SQLiteLog(12285): (1) no such column: _id10 12-31 22:28:17.791: D/AndroidRuntime(12285): Shutting down VM
here is the code : ( of the function getName , which is being used to retrieve the data of column 1 ) [getting error after log.e("2.5".... ) ]
public String getName(long l) { // TODO Auto-generated method stub Log.e("2.4","111111"); String[] column = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS }; Log.e("2.5","111111"); Cursor c = ourDatabase.query(DATABASE_TABLE, column, KEY_ROWID + "" + l, null, null, null, null); Log.e("2.6","111111"); if(c != null) { Log.e("2.7","111111"); c.moveToFirst(); Log.e("2.8","111111"); String name = c.getString(1); Log.e("2.9","111111"); return name; } return null; } public String getHotness(long l) { Log.e("3.1","111111"); // TODO Auto-generated method stub String[] column = new String[]{KEY_ROWID, KEY_NAME, KEY_HOTNESS }; Log.e("3.2","111111"); Cursor c = ourDatabase.query(DATABASE_TABLE, column, KEY_ROWID + "" + l, null, null, null, null); Log.e("3.3","111111"); if(c != null) { Log.e("3.4","111111"); c.moveToFirst(); Log.e("3.5","111111"); String hotness = c.getString(2); Log.e("3.6","111111"); return hotness; } return null; }
And is the code of the activity which is calling this function
case R.id.bgetInfo: String s = sqlRow.getText().toString(); long l = Long.parseLong(s); HotOrNot hon = new HotOrNot(this); hon.open(); String returnedName = hon.getName(l); String returnedHotness = hon.getHotness(l); hon.close(); Log.e("1.2","111111"); sqlName.setText(returnedName); Log.e("1.3","111111"); sqlHotness.setText(returnedHotness); Log.e("1.4","111111"); break;
I think you missed a equal sign at:
Cursor c = ourDatabase.query(DATABASE_TABLE, column, KEY_ROWID + "" + l, null, null, null, null);
Change to:
Cursor c = ourDatabase.query(DATABASE_TABLE, column, KEY_ROWID + " = " + l, null, null, null, null);
Source: Stackoverflow.com