0

我正在尝试获取列 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); ";
4

1 回答 1

0

我认为你的查询是错误的

 String queryz = "SELECT " + "," + MySQLiteHelper.COLUMN_THREADID 
        + " FROM " + MySQLiteHelper.TABLE_NAME 
        + " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;

预期输出“SELECT , COLUMN FROM TABLE WHERE COLUMNID = VALUE”

一个错误的查询

应该是这个

  String queryz = "SELECT " + MySQLiteHelper.COLUMN_THREADID 
            + " FROM " + MySQLiteHelper.TABLE_NAME 
            + " WHERE " + MySQLiteHelper.COLUMN_ID + "=" + ide;

预期输出“SELECT COLUMN FROM TABLE WHERE COLUMNID = VALUE”

检查您的数据库!= null然后是database.isOpen(),如果执行

检查你的cursor!= null然后cursor.getCount() > 0

于 2013-09-12T21:02:37.077 回答