找到数据库异常:发现名称的冲突获取器:isImportantForAccessibility



我正在使用Firebase制作一个购物应用程序。我使用回收器视图来显示数据。每个函数都工作正常,但是每当我单击添加到购物车按钮以获取单独的项目时,它都会引发如下异常:

日志猫

04-02 11:41:57.480 1418-1418/com.app.demo E/Zygote: no v2
04-02 11:42:08.550 1418-1418/com.app.demo E/ViewRootImpl: sendUserActionEvent() mView == null
04-02 11:42:16.368 1418-1418/com.app.hdservices E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app.demo, 
  PID: 1418 com.google.firebase.database.DatabaseException: 
  Found conflicting getters for name: isImportantForAccessibility
  at com.google.android.gms.internal.zzbtg$zza.<init>(Unknown Source)
  at com.google.android.gms.internal.zzbtg.zzi(Unknown Source)
  at com.google.android.gms.internal.zzbtg.zzaz(Unknown Source)
  at com.google.android.gms.internal.zzbtg.zzay(Unknown Source)
  at com.google.firebase.database.DatabaseReference.zza(Unknown Source)
  at com.google.firebase.database.DatabaseReference.setValue(Unknown Source)
  at com.app.hdservices.Veglist$VegViewHolder$3.onClick(Veglist.java:258)
  at android.view.View.performClick(View.java:5716)
  at android.widget.TextView.performClick(TextView.java:10926)
  at android.view.View$PerformClick.run(View.java:22596)
  at android.os.Handler.handleCallback(Handler.java:739)
  at android.os.Handler.dispatchMessage(Handler.java:95)
  at android.os.Looper.loop(Looper.java:148)
  at android.app.ActivityThread.main(ActivityThread.java:7325)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)

蔬菜.java

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_veglist);
        mAuth=FirebaseAuth.getInstance();
        mAuthListener=new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(FirebaseAuth firebaseAuth) {
                if(firebaseAuth.getCurrentUser()==null)
                {
                    Intent i=new Intent(Veglist.this,Login.class);
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(i);
                }
            }
        };
        mainReference = FirebaseDatabase.getInstance().getReference().child("Vegetable");
        cartReference = FirebaseDatabase.getInstance().getReference().child("Cart");
        cartobject = cartReference.child(mAuth.getCurrentUser().getUid()).push();
        mainRecyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        mainRecyclerView.setHasFixedSize(true);
        mainRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mainReference.keepSynced(true);
        cartReference.keepSynced(true);
        cartobject.keepSynced(true);
   Toolbar toolbar = (Toolbar) findViewById(R.id.newToolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setTitle("Fresh Vegetables");
        getSupportActionBar().getThemedContext();
        toolbar.setTitleTextColor(0xFFFFFFFF);
    }
public static class VegViewHolder extends RecyclerView.ViewHolder {
        public View mView;
        private ImageView postImage;
        private TextView quantityBox,postVegName,postPrice,postPriceTag;
        private ImageButton reducequantityButton,increaseQuantityButton;
        private Button add;
        private String mPostKey=null;
        String totalCost;
        private  DatabaseReference cartReference;
        private DatabaseReference cartobject;
        private FirebaseAuth mAuth;

        public VegViewHolder(final View itemView) {
            super(itemView);
            mView = itemView;
            mAuth=FirebaseAuth.getInstance();
            cartReference = FirebaseDatabase.getInstance().getReference().child("Cart");
            cartobject = cartReference.child(mAuth.getCurrentUser().getUid()).push();
            add=(Button)mView.findViewById(R.id.add);
            quantityBox=(TextView)mView.findViewById(R.id.quantity);
            reducequantityButton = (ImageButton) mView.findViewById(R.id.downQuantitybutton);
            increaseQuantityButton = (ImageButton) mView.findViewById(R.id.upQuantitybutton);

                    quantityBox.setText("1");
            increaseQuantityButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    try {
                        int i = Integer.parseInt(quantityBox.getText().toString());
                        int j = i + 1;
                        String k = String.valueOf(j);
                        quantityBox.setText(k);
                    } catch (Exception e) {
                        Toast.makeText(itemView.getContext(), "Quantity can only be a number", Toast.LENGTH_SHORT).show();
                    }
                }
            });
        reducequantityButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                try {
                    if (Integer.parseInt(quantityBox.getText().toString()) <= 1) {
                        Toast.makeText(itemView.getContext(), "Quantity can't be less than 1", Toast.LENGTH_SHORT).show();
                    } else {
                        int i = Integer.parseInt(quantityBox.getText().toString());
                        int j = i - 1;
                        String k = String.valueOf(j);
                        quantityBox.setText(k);
                    }
                } catch (Exception e) {
                    Toast.makeText(itemView.getContext(), "Quantity can only be a number", Toast.LENGTH_SHORT).show();
                }
            }
        });


              add.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                     final ProgressDialog p=new ProgressDialog(mView.getContext());
                      p.setMessage("Wait! Adding to cart ..");
                      p.show();

                      cartobject.child("Image").setValue(postImage);
                      cartobject.child("Name").setValue(postVegName);
                      cartobject.child("Price").setValue(postPrice);
                      cartobject.child("PriceTag").setValue(postPriceTag);
                      cartobject.child("Quantity").setValue(quantityBox.getText().toString());
                      totalCost = String.valueOf(Integer.parseInt(quantityBox.getText().toString()) * Integer.parseInt(postPrice.getText().toString()));
                      cartobject.child("Total").setValue(totalCost).addOnSuccessListener(new OnSuccessListener<Void>() {
                          @Override
                          public void onSuccess(Void aVoid) {
                              p.dismiss();
                              Toast.makeText(mView.getContext(), postVegName + " successfully added to cart! ", Toast.LENGTH_SHORT).show();
                          }
                      });
                  }
              });


            }
        public void setName(String name) {
            postVegName = (TextView) mView.findViewById(R.id.vegName);
            postVegName.setText(name);
        }
        public void setPrice(String price) {
            postPrice = (TextView) mView.findViewById(R.id.VegPrice);
            postPrice.setText(price);

        }
        public void setPriceTag(String priceTag)
        {
            postPriceTag=(TextView)mView.findViewById(R.id.PriceTag);
            postPriceTag.setText(priceTag);
        }
        public void setImage(Context context, String image) {
            postImage = (ImageView) mView.findViewById(R.id.VegImg);
            Picasso.with(context).load(image).into(postImage);
        }



    }

这些对setValue()的调用是问题所在:

cartobject.child("Image").setValue(postImage);
cartobject.child("Name").setValue(postVegName);
cartobject.child("Price").setValue(postPrice);
cartobject.child("PriceTag").setValue(postPriceTag);

您无法在 Firebase 数据库中存储View。 您可能打算存储视图中包含的值,例如:

cartobject.child("Name").setValue(postVegName.getText().toString().trim());

最新更新