sqlite 当我从主要活动转移到另一个活动时,我的应用程序会关闭

okxuctiv  于 2022-11-14  发布在  SQLite
关注(0)|答案(1)|浏览(154)

错误:

E/SQLiteLog: (1) unrecognized token: "4LIMIT" in "SELECT * FROM t_comanda WHERE id = 4LIMIT 1"
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.storder20, PID: 8462
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.storder20/com.example.storder20.VeureActivity}: android.database.sqlite.SQLiteException: unrecognized token: "4LIMIT" (code 1 SQLITE_ERROR): , while compiling: SELECT * FROM t_comanda WHERE id = 4LIMIT 1
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3449)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3601)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

-我有一个主活动的arrayList,你可以添加不同的订单,我的问题是当我想要点击看到这个订单的应用程序关闭。我认为错误来自SQLite数据库中的代码,即:

public Comanda veureComanda (int id){
        DbHelper dbHelper = new DbHelper(context);
        SQLiteDatabase db = dbHelper.getWritableDatabase();

    Comanda comanda = null;
    Cursor cursorComanda = null;

    cursorComanda = db.rawQuery("SELECT * FROM " + TABLE_COMANDA + " WHERE id = " + id + "LIMIT 1", null);

    if (cursorComanda.moveToFirst()){
        comanda = new Comanda();
        comanda.setId(cursorComanda.getInt(0));
        comanda.setNom(cursorComanda.getString(1));
        comanda.setComanda(cursorComanda.getString(2));
        comanda.setUbicació(cursorComanda.getString(3));
    }

    cursorComanda.close();

    return comanda;
}
vohkndzv

vohkndzv1#

关键字“4”和“Limit”之间没有差距正确的请求:

SELECT * FROM t_comanda WHERE id = 4 LIMIT 1

相关问题