- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我一直在使用 ionic 2 native sqlite plugin制作一个基本的应用程序来捕获图像并将其存储到手机本地存储中。当我在 genymotion 模拟器上运行应用程序时,有时会不断收到未捕获的异常错误(似乎来自 sql 插件)。
当我使用 -live 参数(ionic run android -c -l)重新加载应用程序时,通常会发生这种情况。我还注意到存储在应用程序上的数据没有出现(这再次表明在“实时重新加载”时加载存储的数据存在一些问题)我把我得到的错误放在下面的控制台上:
控制台错误消息
[13:28:27] Starting 'html'...
[13:28:27] Finished 'html' after 42 ms
HTML changed: www/build/pages/home/home.html
HTML changed: www/build/pages/map-detail-component/map-detail-component.html
HTML changed: www/build/pages/map-page/map-page.html
0 298305 log Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.
1 298474 group EXCEPTION: Error: Uncaught (in promise): ReferenceError: sqlitePlugin is not defined
2 298475 error EXCEPTION: Error: Uncaught (in promise): ReferenceError: sqlitePlugin is not defined
3 298476 error STACKTRACE:
4 298477 error Error: Uncaught (in promise): ReferenceError: sqlitePlugin is not defined
at resolvePromise (http://192.168.56.1:8100/build/js/zone.js:418:31)
at resolvePromise (http://192.168.56.1:8100/build/js/zone.js:403:17)
at http://192.168.56.1:8100/build/js/zone.js:451:17
at ZoneDelegate.invokeTask (http://192.168.56.1:8100/build/js/zone.js:225:37)
at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (http://192.168.56.1:8100/build/js/app.bundle.js:37360:41)
at ZoneDelegate.invokeTask (http://192.168.56.1:8100/build/js/zone.js:224:42)
at Zone.runTask (http://192.168.56.1:8100/build/js/zone.js:125:47)
at drainMicroTaskQueue (http://192.168.56.1:8100/build/js/zone.js:357:35)
at XMLHttpRequest.ZoneTask.invoke (http://192.168.56.1:8100/build/js/zone.js:297:25)
5 298478 groupEnd
6 298481 error Unhandled Promise rejection:, sqlitePlugin is not defined, ; Zone:, angular, ; Task:, Promise.then, ; Value:, [object Object], ReferenceError: sqlitePlugin is not defined
at http://192.168.56.1:8100/build/js/app.bundle.js:97420:13
at new ZoneAwarePromise (http://192.168.56.1:8100/build/js/zone.js:467:29)
at SQLite.openDatabase (http://192.168.56.1:8100/build/js/app.bundle.js:97419:16)
at new SqlService (http://192.168.56.1:8100/build/js/app.bundle.js:218:21)
at DebugAppView.Object.defineProperty.get (MyApp.template.js:18:67)
at DebugAppView._View_MyApp_Host0.injectorGetInternal (MyApp.template.js:35:79)
at DebugAppView.AppView.injectorGet (http://192.168.56.1:8100/build/js/app.bundle.js:31753:21)
at DebugAppView.injectorGet (http://192.168.56.1:8100/build/js/app.bundle.js:31945:49)
at ElementInjector.get (http://192.168.56.1:8100/build/js/app.bundle.js:31246:33)
at ElementInjector.get (http://192.168.56.1:8100/build/js/app.bundle.js:31249:48)
7 298519 log DEVICE READY FIRED AFTER, 1004, ms
8 298609 log Entering: map-page
9 298620 log ERROR: , {}
当我重新启动模拟器时,这会消失,但有时会在多次使用后再次出现。
我认为这可能是由于在导入插件之前创建了 SQLite 数据库,但我已将插件导入到我的根 app.ts 文件中(如下所示)(整个应用程序可以在此 github repo 中看到) )
根 app.ts
@Component({
template: '<ion-nav [root]="rootPage"></ion-nav>',
// Declare services
providers: [ SqlService ]
})
export class MyApp {
rootPage: any = MapPage;
constructor(platform: Platform) {
platform.ready().then(() => {
StatusBar.styleDefault();
});
}
}
ionicBootstrap(MyApp);
我已将插件的任何使用限制为 sqlService(如下所示)
SQL 服务
import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { SQLite} from 'ionic-native';
@Injectable()
export class SqlService {
private db: SQLite;
private isOpen: boolean;
public constructor() {
if(!this.isOpen){
this.db = new SQLite();
this.db.openDatabase({
name: "data.db",
location: "default"
}).then(() => {
this.db.executeSql("CREATE TABLE IF NOT EXISTS places (id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, img TEXT)", []).then((data) => {
console.log("TABLE CREATED: " + data);
}, (error) => {
console.log("Unable to execute SQL" + error);
});
this.isOpen=true;
});
}
}
public add(title: string, base64Img: string) {
return new Promise((resolve, reject) => {
this.db.executeSql("INSERT INTO places (title, img) VALUES ( '"+ title +"', '"+ base64Img +"')", [])
.then((data) => {
resolve(data);
}, (error) => {
reject(error);
});
});
}
// Remove individual Location
public remove(id: number){
return new Promise((resolve, reject) => {
this.db.executeSql("DELETE FROM places WHERE id = "+ id +";", [])
.then((data) => {
resolve(data);
}, (error) => {
reject(error);
});
});
}
public locDetail(id: number){
return new Promise((resolve, reject) => {
this.db.executeSql("SELECT * FROM places WHERE id = "+ id +";",[])
.then((data) => {
if(data.rows.length===1){
// console.log("ttitle: " + data.rows.item(0).title + " id: " + data.rows.item(0).id + " img: " + data.rows.item(0).img );
let place = [];
place.push({
id: data.rows.item(0).id,
title: data.rows.item(0).title,
img: data.rows.item(0).img
});
resolve(place);
}
}, (error) => {
reject(error);
});
});
}
// Refresh and initialise the places object
public refresh() {
return new Promise((resolve, reject) => {
this.db.executeSql("SELECT * FROM places", []).then((data) => {
let place = [];
if (data.rows.length > 0) {
for (var i = 0; i < data.rows.length; i++) {
place.push({
id: data.rows.item(i).id,
title: data.rows.item(i).title,
img: data.rows.item(i).img
});
}
}
resolve(place);
}, (error) => {
reject(error);
});
}
);
}
}
最佳答案
我最近遇到了同样的问题,请务必检查您的服务平台是否已准备就绪。从“ionic-angular”导入“Platform”并在 promise.then 方法中执行您的 sqlite 交互代码。
关于sqlite - ionic 2 错误 'ReferenceError: sqlitePlugin is not defined',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39547639/
这与PhoneGap sqlite插件有关。 如果在移动设备上执行以下代码,它将仅尝试打开现有数据库,还是在指定数据库不存在的情况下创建一个新数据库? var db = window.sqlitePl
我目前正在使用 Ionic Framework 开发混合应用。 上周一切正常,没有修改插件的任何内容,它就停止工作了,我还没有找到任何线程(只有一个)有任何解决方案或足够好的方法。 我在 Androi
我需要您的帮助来创建一个 SQLite 类,该类允许发送查询并返回结果。 我知道事务/executesql是异步的,我正在尝试解决这个问题。 我写了这段代码: function SQLite(pNam
我实际上正在开发一个正在读取(而不是写入).mbtiles 文件的 cordova 应用程序。这是一个用图 block 归档的数据库,用于显示带有传单的离线 map 。 与文件(称之为 test.mb
我已按照 Gaurav 的建议将“demo.db”文件复制到/data/data/package_name/databases/: 访问:http://gauravstomar.blogspot.co
我一直在使用 ionic 2 native sqlite plugin制作一个基本的应用程序来捕获图像并将其存储到手机本地存储中。当我在 genymotion 模拟器上运行应用程序时,有时会不断收到未
我有一个相对复杂的 sqlcipher 数据库(27 个表)但条目很少(每个表在 50-200 个条目之间)。当我运行 SELECT 语句(与相应 View 相同)、连接 3 个表、执行几个“LIKE
使用 Cordova 版本 3.x 和Android 版本 2.x 到 4.x。 我在想: 我的理解是否正确,即默认情况下所有 Android 设备都有一个用于创建 sqlite 数据库的 sqlit
____ 简介 大家好,首先澄清三点: 我的英语不好,所以我的错误请您提前原谅, 我是新手,所以请原谅我的不准确之处, 我已经搜索并尝试了我在 Internet 上找到的解决方案,但仍然无法解决嵌入预
I'm trying to implement this simple example given in ionic 2 doc: http://ionicframework.com/docs/v2/
我正在尝试使用预先填充的数据库,但我不断收到此错误: 11-10 22:53:35.781: D/CordovaLog(20142): Uncaught TypeError: Cannot call
我在 Android 上使用 cordova-2.0.0 和来自 chbrody 的 SQLite 插件。(https://github.com/chbrody/Cordova-SQLitePlugi
在 goolge 上搜索后,我是使用 sqlite 的数据库移动应用程序的新手 我在 visual studio 中配置我的项目,但我收到两个错误 点击成功后出现第二个错误 我搜索后没有得到任何解决方
我一直在尝试将 sqlite 合并到一个简单的 Ionic 应用程序中,这是我一直遵循的过程: ionic start myApp sidemenu 然后我安装sqlite插件: ionic plu
我正在使用 cordova-sqlite-plugin 为我的应用程序维护本地数据库。下面是我的代码: alert("Running...") document.addEven
我是一名优秀的程序员,十分优秀!