java.util.MissingFormatArgumentException:格式说明符:s [英] java.util.MissingFormatArgumentException: Format specifier: s
本文介绍了java.util.MissingFormatArgumentException:格式说明符:s的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将数据添加到android中的SQLite数据库中,但是却收到错误消息"java.util.MissingFormatArgumentException:格式说明符:s".我试图找出问题所在,但找不到.
I am trying to add data to SQLite database in android, But I am getting error, "java.util.MissingFormatArgumentException: Format specifier: s". I tried to figure out the problem but I can't find it.
按钮OnClickListener可以将数据添加到数据库中.
Button OnClickListener to add data to database.
addToCart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Database(getBaseContext()).addToCart(new Order(
foodId,
foodItem.getName(),
quantity.getNumber(),
foodItem.getPrice(),
foodItem.getDiscount(),
foodItem.getImage()
));
Toast.makeText(ItemDetailsActivity.this, "Item added to your basket.", Toast.LENGTH_SHORT).show();
}
});
添加方法
public void addToCart(Order order){
SQLiteDatabase db = getReadableDatabase();
String query = String.format("INSERT INTO OrderDetails(Productid,ProductName,Quantity,Price,Discount,Image) VALUES('%s','%s','%s','%s','%s','%s');",
order.getProductid(),
order.getProductName(),
order.getQuantity(),
order.getPrice(),
order.getDiscount());
db.execSQL(query);
}
推荐答案
String query = String.format("INSERT INTO OrderDetails(Productid,ProductName,Quantity,Price,Discount,Image) VALUES('%s','%s','%s','%s','%s','%s');",
order.getProductid(),
order.getProductName(),
order.getQuantity(),
order.getPrice(),
order.getDiscount());
您有六个%s
格式的占位符,但仅提供了五个值.
You have six %s
format placeholders but you're supplying only five values.
这篇关于java.util.MissingFormatArgumentException:格式说明符:s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文