java - 错误:无法将 java.lang.String 类型的值转换为 int
问题描述
我刚刚开始使用 Java for Android 进行编程,当我运行我的应用程序时,程序就崩溃了。我知道有一个错误,但我不明白我在哪里错过了从“String”到“Int”的转换(com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的值转换为 int)。
下面是我认为我有转换错误的代码。
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();
}
解决方案
您可以使用Integer.parseInt("your_string")
将字符串转换为整数。
推荐阅读
- java - 获取R2DBC连接Java Spring失败
- flutter - 使用 Flutter for Mediawiki 进行客户端登录
- python - 如何检测价格何时高于先前的高点
- c# - Serilog 属性解构不能始终如一地工作?
- pandas - 向列添加唯一 id 并在来自同一 pandas 数据帧的唯一 id 中包含一个值
- javascript - 查找行数组中最后一列的最后一个值
- css - 如何使svg文本响应
- python - 使用字符串和 int 错误从一年创建日期 - PYTHON
- laravel - Laravel 模型函数最佳价格
- c++ - 有没有办法显示正在使用的未初始化变量?