【问题标题】:NativeScript with angular gives a run time error带有角度的 NativeScript 给出了运行时错误
【发布时间】: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 我试过了。没有结果。但最后我能找到答案。谢谢

标签: nativescript-angular


【解决方案1】:

当我在模拟器中搜索更多内容时,会出现“execSql 不是函数”之类的错误。所以我将其更改为 execSQL,就像我使用 top of the 一样,现在它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-03-18
    • 1970-01-01
    • 2023-03-20
    • 2017-05-16
    • 1970-01-01
    • 2020-08-28
    • 2022-11-10
    相关资源
    最近更新 更多