sqlite: runTest failed Error: Attempt to invoke virtual method 'java.lang.String com.getcapacitor.community.database.sqlite.CapacitorSQLite.echo(java.lang.String)' on a null object reference`
I have an Ionic 6 application using Angular (13).
I followed the steps in the documentation:
- Created a sqlite.service.ts and copied in the service provided.
- Added service to my app.module.ts as a provider.
- Added the following into app.component.ts
initializeApp() {
this.platform.ready().then(async () => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this._sqlite.initializePlugin().then(ret => {
this.initPlugin = ret;
console.log('>>>> in App this.initPlugin ' + this.initPlugin);
});
});
which returns the following when launching the app:
>>>> in App this.initPlugin true
In my page I have the following:
constructor(private translate: TranslateService,
private sqlite: SQLiteService) { }
async ngOnInit(): Promise<void> {
try {
await this.runTest();
} catch (err) {
console.log(`$$$ runTest failed ${err.message}`);
}
}
async runTest(): Promise<void> {
try {
let result: any = await this.sqlite.echo("Hello World");
console.log(" from Echo " + result.value);
// ************************************************
// Create Database No Encryption
// ************************************************
// initialize the connection
let db = await this.sqlite
.createConnection("testEncryption", false, "no-encryption", 1);
// open db testEncryption
await db.open();
await this.sqlite.closeConnection("testEncryption");
return Promise.resolve();
} catch (err) {
return Promise.reject(err);
}
}
When I go to the page I am getting the following error:
``$$$ runTest failed Error: Attempt to invoke virtual method ‘java.lang.String com.getcapacitor.community.database.sqlite.CapacitorSQLite.echo(java.lang.String)’ on a null object reference
Any insight as to what I am doing wrong?
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 35
@ASHBAW @fasterlars In release 3.4.1-1, for developers not using database encryption i add two parameters
iosIsEncryption&androidIsEncryptionin thecapacitor.config.tswhen set to false theKeyChain iOsand theMasterKey Androidwill not be set. This should normally solve that issue. Look at angular-sqlite-app-starter@3.4.1-1Hope this will help
Well right now I am using the latest version of Android Studio (Bumble bee). Before that I was using Arctic Fox, but I really cant remember precicely what version or which SDK´s I was using when I had the error. And didn´t took note of it - sorry.
Yeah that is what I was seeing. Thanks for posting your work around.