question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error on set with array of strings

See original GitHub issue

Current behavior

“com.facebook.react.bridge.ReadableNativeArray cannot be cast to java.lang.String”

When passing an array of string to set [“90:FD:9F:73:11:48”]

If I stringify / parse, like in the legacy, it’s OKAY

Expected behavior

Should work

Repro steps

import AsyncStorageFactory from "@react-native-community/async-storage";
import LegacyStorage from "@react-native-community/async-storage-backend-legacy";

const legacyStorage = new LegacyStorage();

export type StorageModel = {
  bluetoothDevices: string[];
};

const storage = AsyncStorageFactory.create<StorageModel>(legacyStorage, { errorHandler: console.log, logger: console.log() });

export default storage;

Environment

  • Async Storage version: ^2.0.0-rc.1
  • React-Native version: 0.61.5
  • Platform tested: Only tested on android
  • Logs/Error that are relevant:

“com.facebook.react.bridge.ReadableNativeArray cannot be cast to java.lang.String”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
mikunimarucommented, Jan 18, 2020

In relation to this, I have found a problem that does not catch when writing fails.

    storage
      .set("test", ["a", "b", "c"])
      .then(async () => {
        // Processing to be called when writing is successful.
        const array = await storage.get("test");
        console.log("set success");
        console.log(array);
      })
      .catch(() => {
        // Processing to be called when writing fails.
        console.log("set error");
      });

Execution result

# set success
# null

My environment is the same as the topic contributor.

0reactions
krizzucommented, Apr 12, 2020

“Legacy Storage” is actually using current version of AsyncStorage (v1). So every value has to be stringified before saving and parsed before reading.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error on set with array of strings · Issue #269 - GitHub
Current behavior "com.facebook.react.bridge.ReadableNativeArray cannot be cast to java.lang.String" When passing an array of string to set ...
Read more >
5. Common Errors Using Arrays
When you pass an array to a function, the function in general has no idea how long it is. This is why C-strings...
Read more >
String array error - java - Stack Overflow
Array size is static in nature, nameArray is declared with size zero as static size variable has no initialization, it would get default...
Read more >
Processing array variable results in error in the For-Each loop
Solved: Hi Folks, I'm running into a strange issue where Power Automate complains about the array variable as follows: 'foreach' expression.
Read more >
ValueError: Setting an Array Element with a Sequence in Python
For example, if we have an array of strings and try to set one of its elements with a number, then this error...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found