1
votes

I'm new to FireStore, and when I was trying to insert a data using Hashmap it is showing error.

This is the line which I'm adding to my firestore:

Map map = new HashMap<>();

    map.put("And","What");
    map.put("So","What Bro");

    firebaseFirestore.collection("mycollection").document("mydocument").set(map).addOnSuccessListener(new OnSuccessListener<Void>() {
        @Override
        public void onSuccess(Void aVoid) {
            Toast.makeText(ContactActivity.this, "Success", Toast.LENGTH_SHORT).show();
        }
    }).addOnFailureListener(new OnFailureListener() {
        @Override
        public void onFailure(@NonNull Exception e) {
            Toast.makeText(ContactActivity.this, "Failure", Toast.LENGTH_SHORT).show();
        }
    });

And the error is:


E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1 Process: com.example.myapp, PID: 13076 java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/common/base/CharMatcher; at com.google.common.base.Splitter.on(Splitter.java:125) at io.grpc.internal.GrpcUtil.(GrpcUtil.java:203) at io.grpc.internal.AbstractManagedChannelImplBuilder.(AbstractManagedChannelImplBuilder.java:84) at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:48) at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:27) at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:73) at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(com.google.firebase:firebase-firestore@@21.4.3:113) at com.google.firebase.firestore.remote.GrpcCallProvider.lambda$initChannelTask$6(com.google.firebase:firebase-firestore@@21.4.3:256) at com.google.firebase.firestore.remote.GrpcCallProvider$$Lambda$5.call(com.google.firebase:firebase-firestore@@21.4.3) at com.google.android.gms.tasks.zzv.run(Unknown Source) at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(com.google.firebase:firebase-firestore@@21.4.3:54) at com.google.firebase.firestore.util.ThrottledForwardingExecutor$$Lambda$1.run(com.google.firebase:firebase-firestore@@21.4.3) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:818) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.common.base.CharMatcher" on path: DexPathList[[zip file "/data/app/com.example.myapp-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469) at com.google.common.base.Splitter.on(Splitter.java:125)  at io.grpc.internal.GrpcUtil.(GrpcUtil.java:203)  at io.grpc.internal.AbstractManagedChannelImplBuilder.(AbstractManagedChannelImplBuilder.java:84)  at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:48)  at io.grpc.okhttp.OkHttpChannelProvider.builderForTarget(OkHttpChannelProvider.java:27)  at io.grpc.ManagedChannelBuilder.forTarget(ManagedChannelBuilder.java:73)  at com.google.firebase.firestore.remote.GrpcCallProvider.initChannel(com.google.firebase:firebase-firestore@@21.4.3:113)  at com.google.firebase.firestore.remote.GrpcCallProvider.lambda$initChannelTask$6(com.google.firebase:firebase-firestore@@21.4.3:256)  at com.google.firebase.firestore.remote.GrpcCallProvider$$Lambda$5.call(com.google.firebase:firebase-firestore@@21.4.3)  at com.google.android.gms.tasks.zzv.run(Unknown Source)  at com.google.firebase.firestore.util.ThrottledForwardingExecutor.lambda$execute$0(com.google.firebase:firebase-firestore@@21.4.3:54)  at com.google.firebase.firestore.util.ThrottledForwardingExecutor$$Lambda$1.run(com.google.firebase:firebase-firestore@@21.4.3)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  at java.lang.Thread.run(Thread.java:818)  Suppressed: java.lang.NoClassDefFoundError: com.google.common.base.CharMatcher at dalvik.system.DexFile.defineClassNative(Native Method) at dalvik.system.DexFile.defineClass(DexFile.java:226) at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219) at dalvik.system.DexPathList.findClass(DexPathList.java:321) at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54) ... 17 more Suppressed: java.lang.ClassNotFoundException: com.google.common.base.CharMatcher at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 16 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

1
On which particular line of code are you getting the error?Alex Mamo
@AlexMamo when I try adding this line: firebaseFirestore.collection("mycollection").document("mydocument").set(map)Agent K
I got the solution. After pasting this line of code in apps > Build.gradle file it worked fined. - Here is the code: - implementation group: 'com.google.guava', name: 'guava', version: '28.1-android'Agent K

1 Answers

1
votes

I got the solution. After pasting this line of code in apps > Build.gradle file it worked fined.

Here is the code:

implementation group: 'com.google.guava', name: 'guava', version: '28.1-android'