2

The above error is showing when I want to open the app on my mobile phone. But it works normally on emulator.

The model class is:

data class Product(
    var charge: List<String>? = emptyList(),
    var description: String? = "",
    var id: String? = "",
    var image: List<String>? = emptyList(),
    var name: String? = "",
    var priceA: List<String>? = emptyList(),
    var priceD: List<String>? = emptyList(),
    var quantity: List<String>? = emptyList(),
    var size: List<String>? = emptyList(),
    var tag: List<String>? = emptyList()
) : Parcelable 

Data retrieving code from Firestore DataBase :

db.addSnapshotListener { snapshot, e->
                if(e!=null){
                    return@addSnapshotListener
                }
                productList = snapshot!!.toObjects(Product::class.java)
                adapter = Adapter(productList, this@HomeActivity, ProductInterface::class.java)
                fireStoreList.adapter = adapter
                fireStoreList.setHasFixedSize(true)
                fireStoreList.layoutManager = GridLayoutManager(this@HomeActivity, 2)
                hideProgress()
            }

structure of data in Firestore Database:

image

Logcat :

2021-04-08 22:50:21.404 7509-7509/com.example.modshabuisness E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.modshabuisness, PID: 7509 java.lang.RuntimeException: Could not deserialize object. Expected a List, but got a class java.lang.String (found in field 'image') at com.google.firebase.firestore.util.CustomClassMapper.deserializeError(CustomClassMapper.java:563) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToParameterizedType(CustomClassMapper.java:276) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToType(CustomClassMapper.java:187) at com.google.firebase.firestore.util.CustomClassMapper.access$300(CustomClassMapper.java:54) at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:770) at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(CustomClassMapper.java:741) at com.google.firebase.firestore.util.CustomClassMapper.convertBean(CustomClassMapper.java:542) at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(CustomClassMapper.java:253) at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(CustomClassMapper.java:100) at com.google.firebase.firestore.DocumentSnapshot.toObject(DocumentSnapshot.java:183) at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(QueryDocumentSnapshot.java:116) at com.google.firebase.firestore.QuerySnapshot.toObjects(QuerySnapshot.java:184) at com.google.firebase.firestore.QuerySnapshot.toObjects(QuerySnapshot.java:166) at com.example.modshabuisness.activity.HomeActivity$onCreate$3.onEvent(HomeActivity.kt:93) at com.example.modshabuisness.activity.HomeActivity$onCreate$3.onEvent(HomeActivity.kt:37) at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(Query.java:1133) at com.google.firebase.firestore.Query$$Lambda$3.onEvent(Unknown Source:6) at com.google.firebase.firestore.core.AsyncEventListener.lambda$onEvent$0(AsyncEventListener.java:42) at com.google.firebase.firestore.core.AsyncEventListener$$Lambda$1.run(Unknown Source:6) at android.os.Handler.handleCallback(Handler.java:938) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:255) at android.app.ActivityThread.main(ActivityThread.java:8214) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)

5
  • Are you sure it's that document causing the problem? Your image field doesn't look incorrect. Commented Apr 8, 2021 at 11:22
  • yes link appears in logcat indicates the document. But it works well on emulator. Is it the problem of device? Commented Apr 8, 2021 at 11:28
  • I very much doubt it, but that is very strange... Can you include the code you use to retrieve the data? Commented Apr 8, 2021 at 11:35
  • Yes it is strange. Now i run this app on Samsung device, it works perfectly but on Oppo it doesn't. Commented Apr 8, 2021 at 11:40
  • Share your response plaese Commented Apr 8, 2021 at 17:33

1 Answer 1

1

It seems that when you have more than one Image it response as a List of Images but somehow when you have only one Image it response it as a String thats why you have deserialization error. Unfortunately, the deserializer cannot put a String to a List of Strings

Sign up to request clarification or add additional context in comments.

2 Comments

Now i insert one more image but still the same problem. The same code is running well on other devices but on OPPO F11 PRO it shows the error
I think it is a problem of android 11.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.