0

当我尝试从我的 sqlite 数据库请求信息时,我收到此错误:

07-19 02:17:10.835: E/AndroidRuntime(689): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.bodprod.dkr/de.bodprod.dkr.MediNotmediList}: java.lang.IllegalArgumentException: You must supply an SQL string

我的数据库请求:

public ArrayList<HashMap<String,Object>> getAllNotmedis(){
    ArrayList<HashMap<String,Object>> notmediList = new ArrayList<HashMap<String,Object>>();
    String selectQuery = "SELECT medi_id, medi_wirk, medi_handel FROM dkr_medi_liste ORDER BY medi_wirk";
    Log.d("ALLNOTMEDIS",selectQuery);
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);
    HashMap<String , Object> notmedi_item;
    if (cursor.moveToFirst()) {
        do {
            notmedi_item = new HashMap<String, Object>();
            notmedi_item.put("sql_id", Integer.parseInt(cursor.getString(0)));
            notmedi_item.put("wirk", cursor.getString(1));
            notmedi_item.put("handel", unescape(cursor.getString(2)));
            notmediList.add(notmedi_item);
        } while (cursor.moveToNext());
    }
    cursor.close();
    db.close();
    return notmediList;
} 

这一行产生了错误:

    SQLiteDatabase db = this.getWritableDatabase();

为什么我会变成这个错误?数据库存在并充满了数据......

4

3 回答 3

1

错误出现在该onCreate部分中。

我试图用db.execSQL.

我在这一行得到错误,因为SQLiteDatabase db = this.getWritableDatabase();调用了该onCreate方法。

于 2012-07-19T11:05:03.723 回答
0
java.lang.IllegalArgumentException: You must supply an SQL string

如果您在方法中传递了无效的 Sql Query 语句,则会发生上述异常rawQuery。下面的语句一定有问题:

= "SELECT medi_id, medi_wirk, medi_handel FROM dkr_medi_liste ORDER BY medi_wirk";
于 2012-07-19T02:57:29.707 回答
0

您应该创建数据库适配器,作为您的应用程序和数据库之间的连接

于 2012-07-19T02:58:33.717 回答