错误:(93,34)错误:构造函数类Request中的请求不能应用于给定类型的原因:实际和形式参数列表的长度不同

时间:2017-09-24 07:48:55

标签: java android firebase

我正在研究firebase项目,我遇到了这个错误 它在编译过程中不断显示此错误。

Error:(93, 34) error: constructor Request in class Request cannot be applied to given types; required: Uri,int,String,List<Transformation>,int,int,boolean,boolean,boolean,float,float,float,boolean,Config,Priority found: String,String,String,String,List<Order> reason: actual and formal argument lists differ in length

这是我的购物车类

  

public class Cart扩展了AppCompatActivity {

RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference requests;
TextView txtTotalPrice;
FButton btnPlace;
List<Order> cart = new ArrayList<>();
CartAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_cart);

    // init firebase
    database = FirebaseDatabase.getInstance();
    requests = database.getReference("Requests");

    //Init
    recyclerView = (RecyclerView) findViewById(R.id.listCart);
    recyclerView.setHasFixedSize(true);
    layoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(layoutManager);

    txtTotalPrice = (TextView) findViewById(R.id.total);
    btnPlace = (FButton) findViewById(R.id.btnPlaceOrder);

    btnPlace.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showAlertDialog();
        }
    });

    loadListFood();
}

private void showAlertDialog() {

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(Cart.this);
    alertDialog.setTitle("One More Step!");
    alertDialog.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);
    alertDialog.setView(edtAddress);//Add edit Text to alert dialog
    alertDialog.setIcon(R.drawable.ic_shopping_cart_black_24dp);

    alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            //Create new Request
            Request request = new Request(
                    Common.currentUser.getPhone(),
                    Common.currentUser.getName(),
                    edtAddress.getText().toString(),
                    txtTotalPrice.getText().toString(),
                    cart
            );
            //Submit to Firebase
            //We will using System.CurrentMilli to key
            requests.child(String.valueOf((System.currentTimeMillis()))).setValue(request);
            //Delete Cart
            new Database(getBaseContext()).cleanCart();
            Toast.makeText(Cart.this, "Thank you , Order Placed", Toast.LENGTH_SHORT).show();
            finish();
        }
    });

    alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });
    alertDialog.show();

}

private void loadListFood() {

    cart = new Database(this).getCarts();
    adapter = new CartAdapter(cart, this);
    recyclerView.setAdapter(adapter);

    //calculate total price
    int total = 0;
    for (Order order : cart)
        total += (Integer.parseInt(order.getPrice())) * (Integer.parseInt(order.getQuantity()));
    Locale locale = new Locale("en", "US");
    NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);

    txtTotalPrice.setText(fmt.format(total));

} }

这是我的构造函数类Request 包game.bakarunlimited.com.androideatit.Model;

  

import java.util.List; / ** *由gaurang于9/23/2017创建。 * /   公共类请求{

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

here the screenshot of error

1 个答案:

答案 0 :(得分:1)

您可以查看Cart课程,并确保已导入正确的Request(只需确保包裹名称与您在Request课程中的位置相匹配文件)
我这样做的原因是因为您当前的Request班级应该接受String, String, String, String, List<Order>来创建该对象,但是它会抛出错误,说它期待Uri,int,String,List,int,int,boolean,boolean,boolean,float,float,float,boolean,Config,Priority让我觉得你正在使用Request

的错误导入