[英]Error: Failed to convert a value of type java.lang.String to int
I have just started now programming in Java for Android, and when I run my app, the programm just crash.我刚刚开始在 Java 中为 Android 编程,当我运行我的应用程序时,程序就崩溃了。 I know have an error but i can't understand where I miss a conversion "String" to "Int" (com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to int).我知道有一个错误,但我不明白我在哪里错过了从“String”到“Int”的转换(com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的值转换为 int)。
Below is the code where I think I have the conversion error.下面是我认为我有转换错误的代码。
private void DisplayAllProducts() {
Query sort_product_in_descending_order = products_reference.orderByChild("counter");
FirebaseRecyclerOptions<products> options = new FirebaseRecyclerOptions.Builder<products>().setQuery(sort_product_in_descending_order, products.class).build();
adapter_products = new FirebaseRecyclerAdapter<products, ProductsViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull ProductsViewHolder productsViewHolder, int position, @NonNull products products) {
final String ProductsKey = getRef(position).getKey();
productsViewHolder.setFullname(products.getFullname());
productsViewHolder.setID(products.getID());
productsViewHolder.setCollection(products.getCollection());
productsViewHolder.setIndustrialCode(products.getIndustrialcode());
productsViewHolder.setQuality(products.getQuality());
productsViewHolder.setDesign(products.getDesign());
productsViewHolder.setColor(products.getColor());
productsViewHolder.setWeight_grs_m2(products.getWeight_grs_m2());
productsViewHolder.setWeight_grs_ml(products.getWeight_grs_ml());
productsViewHolder.setWidth(products.getWidth());
productsViewHolder.setPrice(products.getPrice());
productsViewHolder.setGeneralComposition(products.getGeneralcomposition());
productsViewHolder.setPileComposition(products.getPilecomposition());
//productsViewHolder.setProfileImage(getApplicationContext(), products.getProfileimage());
//productsViewHolder.setProductImage(getApplicationContext(), products.getProductimage());
productsViewHolder.setDate(products.getDate());
productsViewHolder.setTime(products.getTime());
productsViewHolder.mView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent(activity_navigation.this, click_product.class);
i.putExtra("ProductsKey", ProductsKey);
startActivity(i);
}
});
}
@NonNull
@Override
public ProductsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.all_products_layout, parent, false);
return new ProductsViewHolder(view);
}
};
rv_navigation_productlist.setAdapter(adapter_products);
adapter_products.startListening();
}
You can use Integer.parseInt("your_string")
to convert String to Integer.您可以使用Integer.parseInt("your_string")
将 String 转换为 Integer。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.