TypeError: undefined is not an object (evaluating 'DBManager.init')
rt012 opened this issue · 10 comments
tried to implement your solution but sadly I get this error message: "TypeError: undefined is not an object (evaluating 'DBManager.init')" when I´m calling:
var sqlite = require('react-native-android-sqlite');
var databaseName = 'data.db';
sqlite.init(databaseName)
.then((_) => {
Logger.log('database initialized.');
}).catch((errorMessage) => {
Logger.log(errorMessage);
});
Do you have any idea? @jbrodriguez @leoabacade
Hi @rt012, the error message seems to indicate that DBManager (which is the code on the Java side) hasn't been initialized/defined.
Did you get any error in the terminal when running $ react-native run-android ?
Can you double check build.gradle, settings.gradle and MainActivity.java to see if they're correctly set up ?
No, dont get any errors when running react native run-android
Mh, also I think my files are all right... :
Maybe it doesn't work because I`m currently developing on windows?
build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.facebook.react:react-native:0.12.+'
compile project(':react-native-android-sqlite')
}
settings.gradle:
rootProject.name = 'ReactNativeTestProject'
include ':app'
include ':react-native-android-sqlite'
project(':react-native-android-sqlite').projectDir = new File(settingsDir, '../node_modules/react-native-android-sqlite')
MainActivity:
...
import io.jbrodriguez.react.*;
...
mReactInstanceManager = ReactInstanceManager.builder()
.setApplication(getApplication())
.setBundleAssetName("index.android.bundle")
.setJSMainModuleName("index.android")
.addPackage(new MainReactPackage())
.addPackage(new RNSQLiteModule())
.setUseDeveloperSupport(BuildConfig.DEBUG)
.setInitialLifecycleState(LifecycleState.RESUMED)
.build();
ok, let's assume your project's name is AwesomeProject.
If you put 'data.db' in AwesomeProject/android/app/src/main/assets/databases, does it work ?
Just created a project named AwesomeProject, followed your instructions but still got the same error message -.- @jbrodriguez
Can you post the output of $ adb logcat | grep 'SQLiteAssetHelper'
I didn't get any filtered output.. seems there is no connection to the module?!
Yes, seems so.
What about the output of $ react-native run-android ?
What do the lines that begin with :react-native-android-sqlite say ?
This maybe months old, but was a solution found? I am also getting the same problem.
Hi @wellingtonblessed, rather than a problem with the module, it looks like a setup issue.
What's your output for $ adb logcat | grep 'SQLiteAssetHelper' ?
$ react-native run-android should have some lines beginning with :react-native-android-sqlite
Let me know.
Open a new issue if needed