簡體   English   中英

錯誤:無法將 java.lang.String 類型的值轉換為 int

[英]Error: Failed to convert a value of type java.lang.String to int

我剛剛開始在 Java 中為 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")將 String 轉換為 Integer。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM