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

标签 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 extends 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));

} }

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

import java.util.List; /** * Created by gaurang on 9/23/2017. */ 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;
} }

here the screenshot of error

最佳答案

你能检查一下你的Cart吗?类并确保您导入了正确的 Request (只需确保包名称与文件顶部的 Request 类匹配)
我之所以这么说是因为你当前的Request类(class)应该在 String, String, String, String, List<Order>创建对象,但是它抛出一个错误,指出其期望 Uri,int,String,List,int,int,boolean,boolean,boolean,float,float,float,boolean,Config,Priority这让我认为您使用了错误的导入 Request

关于java - 错误 :(93, 34) 错误:类 Request 中的构造函数 Request 无法应用于给定类型原因:实际参数列表和形式参数列表的长度不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46387826/

相关文章:

android - Phonegap Build App-播放音频

android - 带有移动 float 操作按钮的 Bottom Sheet

javascript - AngularJS Promise 被拒绝而不等待异步响应(它应该解决)

javascript - 如何从 firebase 中的函数检索数据

javascript - 在 Firebase 中关联多个帐户

Java if- else 字符串.contains 不起作用错误

java - 找不到 TomEE 数据源

Java反编译器

Java中的Android工作室gradle错误

java - 为什么插入查询会导致我的数据流管道停止处理数据库插入?