简体   繁体   English

错误:无法将 java.lang.String 类型的值转换为 int

[英]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.

相关问题 无法将类型java.lang.String的值转换为int - Failed to convert a value of type java.lang.String to int 无法将 java.lang.String 类型的值转换为 int? - Failed to convert a value of type java.lang.String to int? Spring @Value —无法将类型“ java.lang.String”的值转换为所需的类型“ int” [保留] - Spring @Value — Failed to convert value of type 'java.lang.String' to required type 'int' [on hold] 无法将“java.lang.String”类型的属性值转换为属性“id”所需的类型“int” - Failed to convert property value of type 'java.lang.String' to required type 'int' for property 'id' com.google.firebase.database.DatabaseException:无法将 java.lang.String 类型的值转换为 int - com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to int 无法将 java.lang.String 类型的值转换为 int(在 explore_fragment 中) - Failed to convert a value of type java.lang.String to int (in explore_fragment) 无法将“ java.lang.String”的值转换为所需的类型“ myEnum” - Failed to convert value of 'java.lang.String' to required type 'myEnum' 无法转换类型[java.lang.String]的属性值 - Failed to convert property value of type [java.lang.String] 无法将类型java.lang.String的值转换为double - Failed to convert a value of type java.lang.String to double 获取错误:无法反序列化对象。 无法将 java.lang.String 类型的值转换为 long - Getting error : Could not deserialize object. Failed to convert a value of type java.lang.String to long
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM