Android:SQLiteException:并非所有设备上都有错误

时间:2012-10-27 10:22:11

标签: android sqlite exception

我在设备上遇到此错误,而在其他设备上运行良好。这是错误:

Caused by: android.database.sqlite.SQLiteException: not an error
    at android.database.sqlite.SQLiteQuery.nativeFillWindow(Native Method)
    at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:86)
    at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:164)
    at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:156)
    at com.Orange.MakeVisits.Themes.onCreate(Themes.java:162) 

我执行一个查询,并在检查Cursor是否为null的行中,我收到此错误。这是我的代码:

    String stmtGetThemes = "SELECT * FROM pr_fields_descriptor a "
   + "inner join pr_fields_starring b on a.id_fields_descriptor = b.fields_descriptor_id "
   + "where b.starring_id = '"+pos_starring_id+"' and a.theme_id='"+themes_ids[m]+"' order by form_rank";

    Cursor getThemesCursor1 = db.databaseQuery(stmtGetThemes);

    if (getThemesCursor1!=null && getThemesCursor1.getCount()>0){
    //----
    }

和databasequery是这个方法(在扩展SQLiteOpenHelper的类中定义):

public Cursor databaseQuery(String stmt) {
        Cursor cursor = db.rawQuery(stmt, null);
        return cursor;
    }

知道什么可能导致此错误吗?声明不好?为什么它适用于其他设备? 欢迎任何想法。谢谢你的推荐。

2 个答案:

答案 0 :(得分:0)

不要在Query中传递数组类型参数,有时它不起作用

int themes_id = themes_ids[m];

String stmtGetThemes = "SELECT * FROM pr_fields_descriptor a inner join pr_fields_starring b on a.id_fields_descriptor = b.fields_descriptor_id where b.starring_id = '"+pos_starring_id+"' AND a.theme_id = '"+themes_id+"' ORDER BY form_rank";

Cursor getThemesCursor1 = db.databaseQuery(stmtGetThemes);

if (getThemesCursor1 != null && getThemesCursor1.getCount() != 0){
//----
}

答案 1 :(得分:0)

String stmtGetThemes = "SELECT * FROM pr_fields_descriptor a "
   + "inner join pr_fields_starring b on a.id_fields_descriptor = b.fields_descriptor_id "
   + "where b.starring_id = '"+pos_starring_id+"' and a.theme_id='"+themes_ids[m]+"' order by form_rank";

请勿以“;”结束此查询。