I get this error few seconds after the app is loaded (but not always sometimes after few minutes or few downloads). I need to solve this issue.
if more details are needed and/or editing - please tell me and I'll make them.
Exception '-[NSNull length]: unrecognized selector sent to instance 0x1e6c059b0' was thrown while invoking multiSet on target AsyncLocalStorage with params ( ( ( "@Ye-Music:songs", "" ) ), 483 )
The function with AsyncStorage:
allSongs = () => {
console.log('hello function!');
fetch(URL + "/SongsList", {
body: null, //// sending null because its a view from SQL db
method: "POST",
headers: {
Accept: 'application/json',
"Content-type": "application/json; charset=UTF-8"
}
})
.then(res => { return res.json()})
.then((songsResult) => {
AsyncStorage.setItem("@Ye-Music:songs", songsResult.d);
})
.catch(err => {
console.error(err);
});
};
package.json
"dependencies": {
"@expo/samples": "2.1.1",
"expo": "29.0.0",
"react": "16.3.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-29.0.0.tar.gz",
"react-native-elements": "^0.19.1",
"react-native-material-cards": "^1.0.9",
"react-native-music-control": "^0.7.3",
"react-native-music-player-service": "^0.1.4-beta",
"react-native-search-header": "^0.3.0",
"react-native-sound": "^0.10.9",
"react-native-track-player": "^0.2.5",
"react-navigation": "^2.9.3"
},
When calling AsyncStorage, the value needs to be defined. If it's not, you'll get the error you encountered.
Error handling logic (for the undefined case) is probably the best way to go.
if(songsResult && songsResult.d) {
AsyncStorage.setItem("@Ye-Music:songs", songsResult.d);
} else {
// handle error case here
}
Make sure songsResult.d
is not undefined and is a string with a length > 0 !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With