Mientras hago un proyecto en una aplicación de alimentos, tengo un problema con mi método cleanCart (). Aquí está mi seguimiento de pila:

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.

Aquí está mi clase 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();
            }
        });

Para su ayuda para encontrar el error, aquí está mi clase de modelo 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;
    }
}

Y aquí está mi clase Model para 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;
    }
}

Y aquí está mi clase Database.java

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);
    }
}

También encontré una ambigüedad en mi base de fuego donde en el campo de dirección muestra la cantidad total

Requests
     1572338667924
      address: "$1,000.00"

foods
  name:"Tom cruise"
  phone:"0988123388"
  total:"USA"

Pero todavía no puedo encontrar qué hacer para solucionarlo. Estoy abierto a cambios si es necesario.

0
Asif Hossain 29 oct. 2019 a las 10:41

1 respuesta

La mejor respuesta

Es un poco difícil de seguir, pero parece que esto le está dando un error porque su método cleanCart tiene un argumento de Order order que se requiere pasar por su clase de base de datos.

Sin embargo, cuando llama al método, se llama sin ningún parámetro.

Debido a que no está utilizando un objeto Order en su método cleanCart en absoluto, puede eliminar el parámetro del método, así:

Clase de base de datos:

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

    db.execSQL(query);
}
0
user11809641 31 oct. 2019 a las 07:54