java.lang.RuntimeException: Found conflicting getters for name isImportantForAccessibility on class androidx.appcompat.widget.AppCompatImageView

Technical World :

I want to save my image into hash Map so that I could display it in CartActivity but it is showing this error

2020-03-30 17:26:55.420 28869-28869/com.example.naturalmart E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.naturalmart, PID: 28869
    java.lang.RuntimeException: Found conflicting getters for name isImportantForAccessibility on class androidx.appcompat.widget.AppCompatImageView
        at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-firestore@@21.4.1:629)
        at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-firestore@@21.4.1:377)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@21.4.1:177)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@21.4.1:140)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:firebase-firestore@@21.4.1:104)
        at com.google.firebase.firestore.util.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:firebase-firestore@@21.4.1:78)
        at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(com.google.firebase:firebase-firestore@@21.4.1:231)
        at com.google.firebase.firestore.UserDataReader.parseSetData(com.google.firebase:firebase-firestore@@21.4.1:75)
        at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@21.4.1:166)
        at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:firebase-firestore@@21.4.1:146)
        at com.example.naturalmart.ProductDetailsActivity.addingToCartList(ProductDetailsActivity.java:200)
        at com.example.naturalmart.ProductDetailsActivity.access$300(ProductDetailsActivity.java:60)
        at com.example.naturalmart.ProductDetailsActivity$2.onClick(ProductDetailsActivity.java:124)
        at android.view.View.performClick(View.java:6319)
        at android.widget.TextView.performClick(TextView.java:11202)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:967)
        at android.view.View$PerformClick.run(View.java:23995)
        at android.os.Handler.handleCallback(Handler.java:751)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6816)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1455)

My ProductDetailsActivity.java File

package com.example.naturalmart;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.icu.text.CaseMap;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.cepheuen.elegantnumberbutton.view.ElegantNumberButton;
import com.example.naturalmart.Model.Products;
import com.example.naturalmart.Prevalent.Prevalent;
import com.facebook.shimmer.ShimmerFrameLayout;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.firestore.CollectionReference;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.FirebaseFirestoreException;
import com.google.firebase.firestore.Query;
import com.google.firebase.firestore.QuerySnapshot;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;
import com.squareup.picasso.Downloader;
import com.squareup.picasso.Picasso;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;

public class ProductDetailsActivity extends AppCompatActivity {
    private Button addToCartButton;
    private FirebaseAuth fAuth;
    private FirebaseUser fUser;
    private FirebaseFirestore firebaseFirestore;
    private ImageView productImage;
    private Products products;
    private ElegantNumberButton numberButton;
    private TextView productPrice, productDescription, productName;
    private String productID = "", state = "Normal";
    private FloatingActionButton addToWishlistButton;
    private ShimmerFrameLayout shimmerDetails;

    private static boolean ALREADY_ADDED_TO_WISHLIST = false;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_details);

        Toolbar toolbar3 = (Toolbar) findViewById(R.id.toolbar3);
        setSupportActionBar(toolbar3);

        String title3 = getIntent().getStringExtra("pname");
        toolbar3.setTitle(title3);

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setDisplayShowHomeEnabled(true);

        productID = getIntent().getStringExtra("pid");

        addToCartButton = (Button) findViewById(R.id.pd_add_to_cart_button);
        numberButton = (ElegantNumberButton) findViewById(R.id.number_btn);
        productImage = (ImageView) findViewById(R.id.product_image_details);
        productName = (TextView) findViewById(R.id.product_name_details);
        productDescription = (TextView) findViewById(R.id.product_description_details);
        productPrice = (TextView) findViewById(R.id.product_price_details);

        fAuth = FirebaseAuth.getInstance();
        fUser = fAuth.getCurrentUser();
        firebaseFirestore = FirebaseFirestore.getInstance();


        addToWishlistButton = findViewById(R.id.add_to_wishlist_btn);
        shimmerDetails = findViewById(R.id.shimmer_details);

        shimmerDetails.startShimmer();

        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                getProductDetails(productID);
            }
        }, 2000);


        addToCartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (state.equals("Order Placed")) {
                    Toast.makeText(ProductDetailsActivity.this, "you can not purchase more products, until your order is shipped or confirmed.", Toast.LENGTH_LONG).show();
                } else {
                    addingToCartList();
                }
                addingToCartList();
            }
        });
        addToWishlistButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (ALREADY_ADDED_TO_WISHLIST) {
                    ALREADY_ADDED_TO_WISHLIST = false;
                    addToWishlistButton.setSupportImageTintList(ColorStateList.valueOf(Color.parseColor("#B5B5B5")));
                } else {
                    ALREADY_ADDED_TO_WISHLIST = true;
                    addToWishlistButton.setSupportImageTintList(getResources().getColorStateList(R.color.colorPrimary));
                }
            }
        });
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.search_and_cart, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        if (id == R.id.action_cart) {
            Intent intent = new Intent(ProductDetailsActivity.this, CartActivity.class);
            startActivity(intent);
        } else if (id == R.id.action_search) {
            Intent intent = new Intent(ProductDetailsActivity.this, SearchProductsActivity.class);
            startActivity(intent);
        }

        super.onBackPressed();
        return true;
    }


    @Override
    protected void onStart() {
        super.onStart();

        CheckOrderState();
    }

    private void addingToCartList()
    {
        String saveCurrentTime, saveCurrentDate;

        FirebaseFirestore firebaseFirestore = FirebaseFirestore.getInstance();
        CollectionReference cartListRef = firebaseFirestore.collection("Cart List");

        Calendar calForDate = Calendar.getInstance();
        SimpleDateFormat currentDate = new SimpleDateFormat("MMM dd, yyyy");
        saveCurrentDate = currentDate.format(calForDate.getTime());

        SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm:ss a");
        saveCurrentTime = currentDate.format(calForDate.getTime());


        final HashMap<String, Object> cartMap = new HashMap<>();
        cartMap.put("pid", productID);
        cartMap.put("pname", productName.getText().toString());
        cartMap.put("price", productPrice.getText().toString());
        cartMap.put("date", saveCurrentDate);
        cartMap.put("time", saveCurrentTime);
        cartMap.put("quantity", numberButton.getNumber());
        cartMap.put("discount", "");
        cartMap.put("image", productImage);


        cartListRef.document(fAuth.getCurrentUser().getPhoneNumber())
                .set(cartMap)
                .addOnCompleteListener(new OnCompleteListener<Void>() {
                    @Override
                    public void onComplete(@NonNull Task<Void> task) {
                        if (task.isSuccessful()) {
                            cartListRef.document(fAuth.getCurrentUser().getPhoneNumber())
                                    .set(cartMap)
                                    .addOnCompleteListener(new OnCompleteListener<Void>() {
                                        @Override
                                        public void onComplete(@NonNull Task<Void> task) {
                                            if (task.isSuccessful()) {
                                                Toast.makeText(ProductDetailsActivity.this, "Added to Cart List.", Toast.LENGTH_SHORT).show();

                                                Intent intent = new Intent(ProductDetailsActivity.this, HomeActivity.class);
                                                startActivity(intent);
                                            }
                                            else
                                            {
                                                Toast.makeText(ProductDetailsActivity.this, "error!!!", Toast.LENGTH_SHORT).show();
                                            }
                                        }
                                    });
                        }
                    }
                });
    }


    private void getProductDetails(String productID) {

        firebaseFirestore = FirebaseFirestore.getInstance();
        DocumentReference documentReference = firebaseFirestore.collection("Products").document(productID);

        documentReference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
            @Override
            public void onSuccess(DocumentSnapshot documentSnapshot) {
                if (documentSnapshot.exists()) {
                    Products products = documentSnapshot.toObject(Products.class);

                    productName.setText(documentSnapshot.getString("pname"));
                    productPrice.setText(products.getPrice());
                    productDescription.setText(products.getDescription());
                    Picasso.get().load(products.getImage()).into(productImage);
                }
                else
                {
                    Toast.makeText(ProductDetailsActivity.this, "error!", Toast.LENGTH_SHORT).show();

                }            }
        });
        shimmerDetails.stopShimmer();
        shimmerDetails.setVisibility(View.INVISIBLE);
        addToCartButton.setVisibility(View.VISIBLE);
        numberButton.setVisibility(View.VISIBLE);
    }

    private void CheckOrderState() {
        DocumentReference ordersRef;
        ordersRef = FirebaseFirestore.getInstance().collection("Orders").document(fAuth.getCurrentUser().getPhoneNumber());

        ordersRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() {
            @Override
            public void onSuccess(DocumentSnapshot documentSnapshot) {
                if (documentSnapshot.exists()) {
                    String shippingState = documentSnapshot.getString("state");
                    if (shippingState.equals("shipped"))  {
                        state = "Order Shipped";
                    } else if (shippingState.equals("not shipped")) {
                        state = "Order Placed";
                    }
                }

            }
        });

    }


}

Please tell me what should I do save image URL in my HashMap

I don't know much coding so I have get content from Youtube Videos and Blogs but I can't find this problem

I am getting the error at HashMap at:

final HashMap<String, Object> cartMap = new HashMap<>();
        cartMap.put("pid", productID);
        cartMap.put("pname", productName.getText().toString());
        cartMap.put("price", productPrice.getText().toString());
        cartMap.put("date", saveCurrentDate);
        cartMap.put("time", saveCurrentTime);
        cartMap.put("quantity", numberButton.getNumber());
        cartMap.put("discount", "");
        cartMap.put("image", productImage);

at line:

 cartMap.put("image, productImage);

My Build.Gradle File:

My Build.Gradle file is:

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {

    compileSdkVersion 29
    buildToolsVersion "28.0.3"

    defaultConfig {
        applicationId "com.example.naturalmart"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-analytics:17.2.3'
    implementation 'com.google.firebase:firebase-core:17.2.3'
    implementation 'com.google.firebase:firebase-database:19.2.1'
    implementation 'com.google.firebase:firebase-storage:19.1.1'
    implementation 'com.firebaseui:firebase-ui-database:3.2.2'
    implementation 'com.firebaseui:firebase-ui-firestore:6.2.1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.github.firdausmaulan:GlideSlider:1.5.1'
    implementation 'net.steamcrafted:materialiconlib:1.1.5'
    implementation 'com.github.rey5137:material:1.2.5'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'io.paperdb:paperdb:2.6'
    implementation 'com.cepheuen.elegant-number-button:lib:1.0.2'
    implementation 'com.google.android.material:material:1.2.0-alpha02'
    implementation 'de.hdodenhof:circleimageview:3.1.0'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.navigation:navigation-fragment:2.2.1'
    implementation 'androidx.navigation:navigation-ui:2.2.1'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-firestore:21.4.1'
    implementation 'com.github.bumptech.glide:glide:4.11.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'com.facebook.shimmer:shimmer:0.5.0'
    implementation 'io.reactivex.rxjava3:rxjava:3.0.1'
    api 'com.google.android.material:material:1.2.0-alpha05'
    implementation 'com.google.firebase:firebase-auth:19.3.0'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
Frank van Puffelen :

The problem comes from this line:

cartMap.put("image", productImage);

You've declared productImage as:

private ImageView productImage;

And it's not possible to save an ImageView to Firestore, as Firestore can only contain the data types listed here. The error you get is the Firestore client's way of saying that it doesn't know what to do with the type you're passing in.


If you want to store the image data itself in Firestore, you will have to get the bytes from the image view and store those. But more common these days is to store the image data itself in Cloud Storage through Firebase, and then store the path to that image (or its download URL) in Firestore.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=371331&siteId=1