【发布时间】:2017-05-08 20:24:44
【问题描述】:
我刚刚尝试连接我的本机脚本应用程序。在 app.component.ts 文件中,我创建了我的数据库和两个方法。
export class AppComponent {
private database: any;
private people: Array<any>;
public constructor() {
console.log(" database service constructors");
(new Sqlite("my.db")).then(db => {
db.execSQL("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, firstName TEXT, lastName Text)").then(db => {
this.database = db;
}, error => {
console.log("CREATE TABLE ERROR", error);
})
}, error => {
console.log("CREATE DB ERROR", error);
})}
public insert() {
console.log("Acess Insert Ok");
this.database.execSql("INSERT INTO people (firstName, lastName) VALUES (?,?)", ["Randika", "Perera"]).then(id => {
console.log("Insert Ok");
this.fetch();
}, error => {
console.log("INSERT ERROR: ", error);
})}
public fetch() {
this.database.all("SELECT * FROM people").then(rows => {
this.people = [];
for (let row in rows) {
this.people.push({
"id": rows[row][0],
"firstName": rows[row][1],
"lastName": rows[row][2]
})
}
}, error => {
console.log("SELECTOR ERROR:", error);
});}}
在 app.component.hlml 文件中:
<ActionBar title="My App">
<ActionItem text="Add" (tap)="insert()"></ActionItem>
但是点击添加按钮后会出现类似的错误
W/System.err(10737): at com.tns.Runtime.callJSMethodNative(Native Method)
W/System.err(10737): at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1197)
W/System.err(10737): at com.tns.Runtime.callJSMethodImpl(Runtime.java:1061)
W/System.err(10737): at com.tns.Runtime.callJSMethod(Runtime.java:1047)
W/System.err(10737): at com.tns.Runtime.callJSMethod(Runtime.java:1028)
W/System.err(10737): at com.tns.Runtime.callJSMethod(Runtime.java:1018)
有人可以帮忙吗?
【问题讨论】:
-
堆栈跟踪的相关位丢失。您能否打开提示符并运行
adb logcat,然后再次点击该按钮?我认为它会揭示问题。 -
@EddyVerbruggen 我试过了。没有结果。但最后我能找到答案。谢谢