【问题标题】:My app crashes when add items to cart [closed]将商品添加到购物车时我的应用程序崩溃 [关闭]
【发布时间】:2018-02-26 04:48:13
【问题描述】:

我正在做一个食品订购应用程序,当我添加到购物车时,我的应用程序崩溃了,我正在使用 SQLite 获取购物车数据

我的日志猫 https://codeshare.io/5wOmyJ

我的代码 https://codeshare.io/aVPLK6 https://codeshare.io/aJ69pE

【问题讨论】:

  • 您的插入查询有语法错误,请发布您的查询代码。
  • 在此处发布您的代码
  • 请将您的数据库方法添加到购物车..
  • 在您的 logcat 中看到这些行了吗? “在 android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)”和“在 com.example.loy.queueeater.Database.Database.addToCart(Database.java:59)”。从这里开始检查。
  • 请关闭插入查询结束括号。 INSERT INTO OrderDetail(ProductId,ProductName,Quantity,Price,Discount) VALUES('32','HAWAIIAN PIZZA','1','1000''0');

标签: java android android-studio android-sqlite


【解决方案1】:

使用这个...

public void addToCart(Order order)
{
    SQLiteDatabase db = getReadableDatabase();
    String query = String.format("INSERT INTO OrderDetail(ProductId,ProductName,Quantity,Price,Discount) VALUES('%s','%s','%s','%s''%s'));",
         order.getProductId(),
         order.getProductName(),
            order.getQuantity(),
            order.getPrice(),
            order.getDiscount());
    db.execSQL(query);
}

你错过了这个右括号..

String query = String.format("INSERT INTO OrderDetail(ProductId,ProductName,Quantity,Price,Discount) VALUES('%s','%s','%s','%s''%s'));" //

【讨论】:

  • 好的,我现在试试
  • 如果有效则更新
  • 添加到购物车时仍然无法使用 m
  • 现在显示你的logcat..尝试这个之后..
  • 没关系,先生,我不小心添加了一个额外的括号,非常感谢您的帮助
猜你喜欢
  • 2016-12-19
  • 2020-01-14
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 2018-04-10
  • 1970-01-01
相关资源
最近更新 更多