There is a problem with this code, if the problem is that the db file could not be…
- User
There is a problem with this code, if the problem is that the db file could not be found, how can I fix it?
ERROR TypeError: Cannot convert null value to object
This error is located at: in Teszt (created by SceneView) in StaticContainer in EnsureSingleNavigator (created by SceneView) in SceneView (created by SceneView) in RCTView (created by View) in View (created by DebugContainer) in DebugContainer (created by MaybeNestedStack) in MaybeNestedStack (created by SceneView) in RCTView (created by View) in View (created by SceneView) in RNSScreen (created by AnimatedComponent) in AnimatedComponent in AnimatedComponentWrapper (created by InnerScreen) in Suspender (created by Freeze) in Suspense (created by Freeze) in Freeze (created by DelayedFreeze) in DelayedFreeze (created by InnerScreen) in InnerScreen (created by Screen) in Screen (created by SceneView) in SceneView (created by NativeStackViewInner) in Suspender (created by Freeze) in Suspense (created by Freeze) in Freeze (created by DelayedFreeze) in DelayedFreeze (created by ScreenStack) in RNSScreenStack (created by ScreenStack) in ScreenStack (created by NativeStackViewInner) in NativeStackViewInner (created by NativeStackView) in RNCSafeAreaProvider (created by SafeAreaProvider) in SafeAreaProvider (created by SafeAreaInsetsContext) in SafeAreaProviderCompat (created by NativeStackView) in NativeStackView (created by NativeStackNavigator) in PreventRemoveProvider (created by NavigationContent) in NavigationContent in Unknown (created by NativeStackNavigator) in NativeStackNavigator (created by Page) in EnsureSingleNavigator in BaseNavigationContainer in ThemeProvider in NavigationContainerInner (created by Page) in Page (created by withDevTools(Page)) in withDevTools(Page) in RCTView (created by View) in View (created by AppContainer) in RCTView (created by View) in View (created by AppContainer) in AppContainer in main(RootComponent), js engine: hermes
const Teszt = () => { const [people, setPeople] = useState([]); const db = SQLite.openDatabase({name: 'myDatabase.db', location: 'default'});
useEffect(() => {
// Create a table called people with id as primary key, name, and age db.transaction((txn) => { txn.executeSql( "CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(20), age INT)", ); });}, []);
- Assistant
The code looks fine, and the issue might not be directly related to the database file's location. However, you can try specifying the
dbvariable with a complete path to ensure the SQLite database is created in the correct location. Also, make sure the necessary dependencies are installed, i.e.,react-native-sqlite-storage.First, update the database initialization code like this:
const db = SQLite.openDatabase({ name: 'myDatabase.db', location: 'default', createFromLocation:"~myDatabase.db", });Next, make sure you've installed the
react-native-sqlite-storagepackage:npm install react-native-sqlite-storageAlso, please make sure you've followed the linking and setup instructions for
react-native-sqlite-storage, as it's a native module and requires additional steps for iOS and Android. You can find the setup guide in the official documentation: - User
Can you write me the most optimized sqlite database code sample for expo react native?
- Assistant