open数据库错误:无法将空值转换为对象

问题描述 投票:0回答:1

我正在使用 react-native-sqlite-storage,想使用 JSON 函数和运算符,在阅读问题后我发现我需要使用 Android 原生 SQLite #480。然后我更改了 react-native.config.js 以使用与库捆绑的 SQLite。进行一些调整以运行文档中给定的测试示例,但在打开数据库时出错:

 OPEN database: Test.db
 LOG  SQLite.open({"name":"Test.db","dblocation":"nosync"})
 ERROR  TypeError: Cannot convert null value to object, js engine: hermes

我正在使用 Windows 和 RN Android 模拟器(默认脚本:npm run android)和这些包的版本:

"dependencies": {
    "deprecated-react-native-listview": "^0.0.8",
    "react": "18.1.0",
    "react-native": "0.70.3",
    "react-native-sqlite-storage": "^6.0.1"
  },

我想上传堆栈跟踪,但我不知道如何从设备中提取它。从设备中输出的堆栈中的一些步骤,它们都与 sqlite.core.js 文件相关:

1 --- plugin.exec
2 --- SQLitePlugin.prototype.open
3 --- SQLitePlugin
4 --- argsArray$argument_0

我不知道是不是函数本身 (openDatabase) 无法识别 args,如果我必须使用另一个函数,或者是因为我没有通过将数据库复制到特定文件夹来预先填充数据库。

react-native.config.js

module.exports = {
    dependency: {
        platforms: {
            ios: {
                project: './platforms/ios/SQLite.xcodeproj'
            },
            /* 
            // default config
            android: {
                sourceDir: './platforms/android'
            },
            */
            // changed
            android: {
                sourceDir:  "../node_modules/react-native-sqlite-storage/platforms/android-native",
                packageImportPath: "import io.liteglue.SQLitePluginPackage;",
                packageInstance: "new SQLitePluginPackage()"
            },
            windows: {
                sourceDir: './platforms/windows',
                solutionFile: 'SQLitePlugin.sln',
                projects: [
                  {
                    projectFile: 'SQLitePlugin/SQLitePlugin.vcxproj',
                    directDependency: true,
                  }
                ],
            }
        }
    }
}
android react-native sqlite react-native-sqlite-storage opendatabase
1个回答
0
投票

我也遇到了这个错误。就我而言,这只是一个操作顺序问题。这个错误是我在安装react-native-sqlite-storage包之前启动APP时出现的。当我重新启动APP时,这个错误消失了。

参考范例: https://blog.logrocket.com/using-sqlite-with-react-native/ https://aboutreact.com/example-of-sqlite-database-in-react-native/

© www.soinside.com 2019 - 2024. All rights reserved.