了java.lang.RuntimeException:发现阶级冲突的进行名称isImportantForAccessibility干将androidx.appcompat.widget.AppCompatImageView

技术的世界:

我想我的图像保存到哈希表,这样我可以在CartActivity显示,但其显示的错误

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:[email protected]@21.4.1:629)
        at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:[email protected]@21.4.1:377)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:[email protected]@21.4.1:177)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:[email protected]@21.4.1:140)
        at com.google.firebase.firestore.util.CustomClassMapper.serialize(com.google.firebase:[email protected]@21.4.1:104)
        at com.google.firebase.firestore.util.CustomClassMapper.convertToPlainJavaTypes(com.google.firebase:[email protected]@21.4.1:78)
        at com.google.firebase.firestore.UserDataReader.convertAndParseDocumentData(com.google.firebase:[email protected]@21.4.1:231)
        at com.google.firebase.firestore.UserDataReader.parseSetData(com.google.firebase:[email protected]@21.4.1:75)
        at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:[email protected]@21.4.1:166)
        at com.google.firebase.firestore.DocumentReference.set(com.google.firebase:[email protected]@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)

我ProductDetailsActivity.java文件

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";
                    }
                }

            }
        });

    }


}

请告诉我该怎么办保存图像URL在我的HashMap

我不知道很多编码,所以我必须获得来自YouTube的视频和博客内容,但我无法找到这个问题

我正在错误的HashMap中的:

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);

在行:

 cartMap.put("image, productImage);

我的build.gradle文件:

我的build.gradle文件是:

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:[email protected]'
    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'
}
弗兰克Puffelen:

这个问题来源于此行:

cartMap.put("image", productImage);

你已经声明productImage如下:

private ImageView productImage;

而且它无法保存ImageView到公司的FireStore,作为公司的FireStore只能包含列出的数据类型在这里你得到的错误是说,它不知道如何处理你传递的类型做的公司的FireStore客户端的方式。


如果你想存储的图像数据本身在公司的FireStore,你必须得从图像视图字节和存储那些。但更常见的这些天是通过火力地堡图像数据本身在云存储存储,然后存储在公司的FireStore的路径图像(或它的下载地址)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

TOP 榜单

热门标签

归档