I am trying to get the value of column threadid where id(which is unique) is equal to the id I am sending to the getthreadid function.threadid contains the values in data type long, But I don't know why my app crashes in doing this,Please help,Thanks in advance.
long id;
long threadid = datasource.getthreadid(id);
Toast.makeText(getActivity(), String.valueOf(threadid), Toast.LENGTH_SHORT).show();
public long getthreadid(long id)
{
String ide = String.valueOf(id);
String queryz = "SELECT " + "," + MySQLiteHelper.COLUMN_THREADID
+ " FROM " + MySQLiteHelper.TABLE_NAME
+ " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;
Cursor cursor = database.rawQuery(queryz, null);
long threadid = cursor.getLong(cursor.getColumnIndex("threadid"));
return threadid;
}
My database create query is:
static final String DATABASE_CREATE = "create table "+"message"+
"( " +"id"+" integer primary key autoincrement,"+ "threadid long,parentid integer,message text not null,messagestatus text); ";
I think your query is wrong
String queryz = "SELECT " + "," + MySQLiteHelper.COLUMN_THREADID
+ " FROM " + MySQLiteHelper.TABLE_NAME
+ " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;
Expected Output "SELECT , COLUMN FROM TABLE WHERE COLUMNID = VALUE " A WRONG QUERY
Should be this
String queryz = "SELECT " + MySQLiteHelper.COLUMN_THREADID
+ " FROM " + MySQLiteHelper.TABLE_NAME
+ " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;
Expected Output "SELECT COLUMN FROM TABLE WHERE COLUMNID = VALUE "
Check for your database!=null and then database.isOpen() and if executes the
check your cursor!= null and then cursor.getCount() > 0