Java 错误:无法将类数据库中的方法cleanCart应用于给定类型

Java 错误:无法将类数据库中的方法cleanCart应用于给定类型,java,android,database,firebase,methods,Java,Android,Database,Firebase,Methods,在食品应用程序上执行项目时,我的cleanCart()方法遇到了问题。这是我的堆栈跟踪: error: method cleanCart in class Database cannot be applied to given types; new Database(getBaseContext()).cleanCart(); ^ required: Order f

在食品应用程序上执行项目时,我的cleanCart()方法遇到了问题。这是我的堆栈跟踪:

error: method cleanCart in class Database cannot be applied to given types;
                new Database(getBaseContext()).cleanCart();
                                              ^
  required: Order
  found: no arguments
  reason: actual and formal argument lists differ in length
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
这是我的Cart.java类

private void showAlertDialogue() {

        AlertDialog.Builder alertDialogue=new AlertDialog.Builder(Cart.this);
        alertDialogue.setTitle("One more step!");
        alertDialogue.setMessage("Enter your address :");



        final EditText edtAddress=new EditText(Cart.this);
        LinearLayout.LayoutParams lp=new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT
        );


        edtAddress.setLayoutParams(lp);
        alertDialogue.setView(edtAddress);  //Add edit text to alert dialog
        alertDialogue.setIcon(R.drawable.ic_shopping_cart_black_24dp);


        alertDialogue.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

                //Create new request

                Request request=new Request(

                        Common.currentUser.getPhone(),
                        Common.currentUser.getName(),
                        txtTotalPrice.getText().toString(),
                        edtAddress.getText().toString(),
                        cart

                );


                //Submit to Firebase
                //We will using System.currentMili to key

                requests .child(String.valueOf(System.currentTimeMillis()))
                        .setValue(request);

//                        .setValue(request);

                //Delete cart

                new Database(getBaseContext()).cleanCart();

                Toast.makeText(Cart.this, "Thank you. Order placed", Toast.LENGTH_SHORT).show();
                finish();
            }
        });
public class Database extends SQLiteAssetHelper {

    private static final String DB_NAME = "EatItDB.db";
    private static final int DB_VER = 1;

    public Database(Context context) {
        super(context, DB_NAME, null, DB_VER);
    }

    public List<Order> getCarts() {
        SQLiteDatabase db = getReadableDatabase();
        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();

        String[] sqlSelect = {"ProductId", "ProductName", "Quantity", "Price", "Discount"};
        String sqlTable = "OrderDetailId";

        qb.setTables(sqlTable);
        Cursor c = qb.query(db, sqlSelect, null, null, null, null, null);

        final List<Order> result = new ArrayList<>();
        if (c.moveToFirst()) {
            do {
                result.add(new Order(c.getString(c.getColumnIndex("ProductId")),
                        c.getString(c.getColumnIndex("ProductName")),
                        c.getString(c.getColumnIndex("Quantity")),
                        c.getString(c.getColumnIndex("Price")),
                        c.getString(c.getColumnIndex("Discount"))

                ));
            } while (c.moveToNext());
        }
        return result;
    }

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

        db.execSQL(query);
    }

    public void cleanCart(Order order) {
        SQLiteDatabase db = getReadableDatabase();
        String query = String.format("DELETE FROM OrderDetail");

        db.execSQL(query);
    }
}
为了帮助您找到bug,这里是我的模型类Order.java

public class Order {
    private String ProductId;
    private String ProductName;
    private String Quantity;
    private String Price;
    private String Discount;

    public Order() {
    }

    public Order(String productId, String productName, String quantity, String price, String discount) {
        ProductId = productId;
        ProductName = productName;
        Quantity = quantity;
        Price = price;
        Discount = discount;
    }

    public String getProductId() {
        return ProductId;
    }

    public void setProductId(String productId) {
        ProductId = productId;
    }

    public String getProductName() {
        return ProductName;
    }

    public void setProductName(String productName) {
        ProductName = productName;
    }

    public String getQuantity() {
        return Quantity;
    }

    public void setQuantity(String quantity) {
        Quantity = quantity;
    }

    public String getPrice() {
        return Price;
    }

    public void setPrice(String price) {
        Price = price;
    }

    public String getDiscount() {
        return Discount;
    }

    public void setDiscount(String discount) {
        Discount = discount;
    }
}
这是我的Request.java模型类

public class Request {

    private String phone;
    private String name;
    private String address;
    private String total;
    private List<Order> foods;  //List of food order

    public Request() {
    }

    public Request(String phone, String name, String address, String total, List<Order> foods) {
        this.phone = phone;
        this.name = name;
        this.address = address;
        this.total = total;
        this.foods = foods;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public List<Order> getFoods() {
        return foods;
    }

    public void setFoods(List<Order> foods) {
        this.foods = foods;
    }
}

但我仍然找不到该怎么做来修复它。如果需要,我愿意接受更改。

这有点难以理解,但这似乎给了您一个错误,因为您的
cleanCart
方法有一个参数
Order-Order
,需要按照数据库类传入该参数

但是,当您调用该方法时,将在不使用任何参数的情况下调用它

因为在
cleanCart
方法中根本没有使用
Order
对象,所以可以从方法中删除参数,如下所示:

数据库类:

public void cleanCart() { // remove parameter
    SQLiteDatabase db = getReadableDatabase();
    String query = String.format("DELETE FROM OrderDetail");

    db.execSQL(query);
}

看起来
数据库
类没有
cleanCart
方法。cleanCart方法写在哪里?兄弟,我现在已经添加了Database.java类。如果需要一些更改,请提出建议。
public void cleanCart(Order-Order){
-接受一个参数,但不确定原因,因为它没有被使用。请帮助大家..密切关注
public void cleanCart(Order-Order){
方法。它有一个参数
Order-Order
。但是该参数没有用。您可以删除它。
public void cleanCart() { // remove parameter
    SQLiteDatabase db = getReadableDatabase();
    String query = String.format("DELETE FROM OrderDetail");

    db.execSQL(query);
}