ERROR TypeError: Cannot convert null value to object This error is located at: in Teszt…
- User
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 ERROR TypeError: Cannot convert null value to object
const TipusButton = ({tipus, tantargy}) => { const navigation = useNavigation();
const onPressHandler = () => { navigation.navigate('Teszt', {tantargy: tantargy}); }import React, {useState, useEffect} from 'react'; import {View, Text, Button} from 'react-native'; import SQLite from 'react-native-sqlite-storage';
const Teszt = () => { const [people, setPeople] = useState([]);
useEffect(() => { // Initialize the SQLite database const db = SQLite.openDatabase( { name: 'myDatabase.db', location: 'default', }, () => console.log('Database opened successfully'), (error) => console.log('Error opening database:', error), );
// 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'); });}, []);
const addPerson = () => { const db = SQLite.openDatabase({name: 'myDatabase.db', location: 'default'});
// Insert a person into the people table db.transaction((txn) => { txn.executeSql( 'INSERT INTO people (name, age) VALUES (?, ?)', ['John Doe', 30], ); }); - Assistant
Your code seems to have an unexpected syntax issue in the
CREATE TABLEquerytxn.executeSql. The correct syntax for creating a table namedpeoplewith the columnsid,name, andageis as follows:txn.executeSql( "CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR(20), age INT)", );Please note that you missed a closing parenthesis
)at the end of your query.Here's the corrected
useEffectwith the fixed query:useEffect(() => { // Initialize the SQLite database const db = SQLite.openDatabase( { name: 'myDatabase.db', location: 'default', }, () => console.log('Database opened successfully'), (error) => console.log('Error opening database:', error), ); // 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)", ); }); }, []);If you still encounter the error after making the above changes, please provide more context, including more of the surrounding code, and I'll be happy to further assist.
- User
- Assistant
The error you are encountering seems to be unrelated to the SQLite code you have provided, but may be related to the navigation setup or rendering of your screens. To better understand the error, let's try a few debugging steps:
-
Make sure that you have imported all the required components and functions in your files.
-
Test your navigation setup by simplifying your screens. Replace the
Tesztscreen component with a simple dummy component to see if there's a specific issue with theTesztcomponent itself or if it's related to the navigation setup.
Create a simple component called :
-
- User
So I tried, the navigation is working, there is something wrong with the sql code
import React, {useState, useEffect} from 'react'; import {View, Text, Button, SafeAreaView} from 'react-native'; import SQLite from 'react-native-sqlite-storage'; import { useNavigation } from '@react-navigation/native'; import DummyScreen from './DummyScreen';
const Teszt = () => { const [people, setPeople] = useState([]); const db = SQLite.openDatabase({name: 'myDatabase.db', location: 'default'});
useEffect(() => { // Initialize the SQLite database const db = SQLite.openDatabase( { name: 'myDatabase.db', location: 'default', }, () => console.log('Database opened successfully'), (error) => console.log('Error opening database:', error), );
// 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)", ); });}, []);
const addPerson = () => { // Insert a person into the people table db.transaction((txn) => { txn.executeSql( 'INSERT INTO people (name, age) VALUES (?, ?)', ['John Doe', 30], ); }); };
- Assistant