Home » Java » java – ArrayList cannot be cast to ReadableArray error in React-Nativce-Exceptionshub

java – ArrayList cannot be cast to ReadableArray error in React-Nativce-Exceptionshub

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a bridge between React-native and android which I am using to return a promise which is an ArrayList but I am facing this error: ArrayList cannot be cast to ReadableArray

This is the function in Android:

@ReactMethod
public void getLocks(Callback callback) {
    WritableNativeArray arguments = new WritableNativeArray();
    arguments.pushArray((ReadableArray) arrayCars.jsonResponse);
    callback.invoke("arr", arguments);
 }

this is what I have in arrayCars.json.

Response:

Array of cars: [{
 "error": "",
 "cars": [{
  "id": 0,
  "tagid": "sdfsdfsd",
  "plate": "ertt",
  "sms": "sdfsdf",
  "latitude": "55.618331",
  "longitude": "13.010308"
 }, {
  "id": 1,
  "tagid": "ertert",
  "plate": "TEST",
  "sms": "34535",
  "latitude": "55.8444",
  "longitude": "11.841"
 }, {
  "id": 2,
  "tagid": "435345345345fh",
  "plate": "TEST2",
  "sms": "44534543",
  "latitude": "55345345781",
  "longitude": "12.16456554"
 }]
}]

Any suggestion is highly appreciated!

How to&Answers: