react-native - React Native - 异常'- [NSNull length]:在调用multiSet时抛出无法识别的选择器发送到实例0x1e6c059b0'
问题描述
我在应用程序加载几秒钟后收到此错误(但有时在几分钟或几次下载后并不总是如此)。我需要解决这个问题。
如果需要更多细节和/或编辑 - 请告诉我,我会做的。
异常'-[NSNull length]: unrecognized selector sent to instance 0x1e6c059b0' was throwed while invoking multiSet on target AsyncLocalStorage with params (( ("@Ye-Music:songs", "")), 483
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);
});
};
包.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"
},
解决方案
调用 AsyncStorage 时,需要定义值。如果不是,您将收到遇到的错误。
错误处理逻辑(对于未定义的情况)可能是最好的方法。
if(songsResult && songsResult.d) {
AsyncStorage.setItem("@Ye-Music:songs", songsResult.d);
} else {
// handle error case here
}
推荐阅读
- angular - 无法显示数组数据
- scala - 如果自上一个检查点创建以来没有更改,如何调用 DeltaLog checkpoint()?
- pyspark - 如何在 Pyspark MLlib 模型中允许 NULL/NaN?
- python-3.x - 有没有办法并行运行子进程?
- java - 如何调试jvm内存泄漏?
- ios - 如何在 Swift 中重构重复的 Firestore 文档 ID?
- r - 如何创建具有两个向量中存在的字符链的变量
- mongodb - Mongo db 请求不是基于哈希的
- excel - 通过 VBA 实现索引匹配函数的 Fillfdown 方法
- node.js - 如何从另一个模块发射?socket.io、node.js