【问题标题】:Android sqlite unrecognized token exception [duplicate]Android sqlite无法识别的令牌异常[重复]
【发布时间】:2012-12-29 05:59:59
【问题描述】:

我正在尝试从 sqlite 表中获取我的 android 代码中的一些数据。我得到一个无法识别的令牌异常。请帮忙。 这是我的代码的相关部分:

private static final String APPS_CREATE =
        "create table applist (" +
                    "_id integer primary key, " +
                    "deviceid int(10) not null," +
                    "catid int(10)," +
                         ............



private static final String APPCNT_CREATE =
            "create table appcntlist (" +
                    "_id integer primary key, "+
                    "appcntid int , " +
                    "cntappid int);";
    .........................

      public Cursor fetchCntNotes(String cnt){

        Cursor appfinlist=null;

        Cursor temp=mDb.query(CNT_TABLE, new String[]{KEY_ROWID}, KEY_CNTNM + "=\"" + cnt + "\"", null, null , null, null);
        Cursor applist;

        if(temp.moveToFirst()){
            id=temp.getInt(temp.getColumnIndexOrThrow(DbAdapter.KEY_ROWID));
            Log.d("amit","countryname id: "+ id);

            applist=mDb.rawQuery("SELECT appcntid FROM appcntlist WHERE cntappid = "+id, null);
            if(applist.moveToFirst()){
                int[] cntin=new int[applist.getCount()];
                for(int i=0;i<applist.getCount();i++){
                    Log.d("amit","countryname id appid: " + applist.getInt(applist.getColumnIndexOrThrow(DbAdapter.KEY_APPCNTID)));
                    cntin[i]=applist.getInt(applist.getColumnIndexOrThrow(DbAdapter.KEY_APPCNTID));
                    Log.d("amit","countryname id cnt var: " + cntin[i]);
                    applist.moveToNext();   
                }
                appfinlist = mDb.rawQuery("SELECT * FROM applist WHERE _id IN "+cntin+")", null);
                return appfinlist;
            }

这是logcat的相关部分

E/AndroidRuntime(6447): 由: android.database.sqlite.SQLiteException: unrecognized token: "[I@406488d0)": ,编译时:SELECT * FROM applist WHERE _id IN [I@406488d0)

【问题讨论】:

  • 看来cntin 变量等于[I@405c6240 字符串。你确定你的原始查询文本是正确的吗?您可以尝试从查询中删除 + cntin 部分。
  • ambit:为什么要在查询末尾附加cntin 变量?
  • 当你使用硬编码的“cntappid=36”时,cntin 的目的是什么
  • 对发布错误代码表示歉意。我试图从我的代码中删除不必要的东西,最后粘贴了我注释代码的一部分。我现在已经编辑了这个问题。请查看它,如果您能提供帮助,请告诉我。谢谢。
  • 投反对票的原因是什么? :(

标签: android android-sqlite


【解决方案1】:

删除cntin 并重试我认为查询无效,在查询字符串末尾附加了变量。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 1970-01-01
    相关资源
    最近更新 更多