我试图获取列threadid的值,其中id(唯一)等于我发送给getthreadid函数的id .threadid包含数据类型long的值,但我不知道为什么我的应用程序崩溃这样做,请帮助,提前谢谢。
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;
}
我的数据库创建查询是:
static final String DATABASE_CREATE = "create table "+"message"+
"( " +"id"+" integer primary key autoincrement,"+ "threadid long,parentid integer,message text not null,messagestatus text); ";
答案 0 :(得分:0)
我认为您的查询错误
String queryz = "SELECT " + "," + MySQLiteHelper.COLUMN_THREADID
+ " FROM " + MySQLiteHelper.TABLE_NAME
+ " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;
错误的查询
String queryz = "SELECT " + MySQLiteHelper.COLUMN_THREADID
+ " FROM " + MySQLiteHelper.TABLE_NAME
+ " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;
检查数据库!= null 然后 database.isOpen(),如果执行
检查光标!= null 然后 cursor.getCount()> 0 强>