2

我的应用程序中有一些代码,但是当我插入表格时出现错误。我不知道为什么。谁能帮我??

这是我的代码:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tambahpenerima);

    data = new dbHelper(this);
    db = data.getWritableDatabase();
    data.createTable(db);

    na = (TextView)findViewById(R.id.na);
    no = (TextView)findViewById(R.id.no);
    pesanx = (EditText)findViewById(R.id.hasilx);

    Bundle paket = getIntent().getExtras();
    nama = paket.getString("nama");
    nomor = paket.getString("nomor");
    hasil = paket.getString("chiper");
    na.setText(nama);
    no.setText(nomor);
    pesanx.setText(hasil);

    pesanKeluar objk = new pesanKeluar(nama, nomor, hasil);
    inputDataK(db, objk);   //here the error    
}
public void inputDataK(SQLiteDatabase db, pesanKeluar k) {
    ContentValues cv = new ContentValues();
    cv.put("nama", k.getNama());
    cv.put("nomortlp", k.getNomorTlp()); //here my modified
    cv.put("chiperteks", k.getChiperteks()); //here my modified
    db.insert("pesanKeluar", null, cv); //here my modified
    db.close();
}
}

我已经修改了我的代码,但我得到了和以前一样的错误。请看一下我的日志错误。

    03-11 17:27:33.704: I/Database(1664): sqlite returned: error code = 
1, msg = table pesanKeluar has no column named chiper
    03-11 17:27:33.725: E/Database(1664): Error inserting 
chiper=00010101 nama=D nomor=536
    03-11 17:27:33.725: E/Database(1664): 
android.database.sqlite.SQLiteException: table pesanKeluar has no column
 named chiper: , while compiling: INSERT INTO pesanKeluar(chiper, nama, 
nomor) VALUES(?, ?, ?);

这是我的 dbHelper.java:

package com.databasesms;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class dbHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "dbenkripsisms.db";

public dbHelper ( Context context) {
    super ( context, DATABASE_NAME, null, 1);
}

public void createTable ( SQLiteDatabase db) {
    db.execSQL("CREATE TABLE if not exists tbPesan (id INTEGER PRIMARY KEY AUTOINCREMENT, plainteks TEXT, key TEXT, chiperteks TEXT);");
    db.execSQL("CREATE TABLE if not exists pesanMasuk (id_pm INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT, nomortlp NUMBER, plainteks TEXT, key TEXT);");
    db.execSQL("CREATE TABLE if not exists pesanKeluar (id_pk INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT, nomortlp TEXT, chiperteks TEXT);");
}

@Override
public void onCreate ( SQLiteDatabase arg0 ) {

}

@Override
public void onUpgrade ( SQLiteDatabase arg0, int arg1, int arg2 ) {

}


} 

这是我的 pesanKeluar.java:

package com.databasesms;

public class pesanKeluar {
private String nama;
private String nomortlp;
private String chiperteks;

public pesanKeluar () {
    super();
}

public pesanKeluar ( String nama, String nomortlp, String chiperteks ) {
    this.nama = nama;
    this.nomortlp = nomortlp;
    this.chiperteks = chiperteks;       
}

public String getNama () {
    return nama;
}

public void setNama ( String nama ) {
    this.nama = nama;
}

public String getNomorTlp () {
    return nomortlp;
}

public void setNomorTlp ( String nomortlp ) {
    this.nomortlp = nomortlp;
}

public String getChiperteks () {
    return chiperteks;
}

public void setChiperteks ( String chiperteks ) {
    this.chiperteks = chiperteks;
}

}
4

7 回答 7

1

尝试上述解决方案,例如替换列名,然后在重新启动应用程序之前清除您的数据。

于 2013-03-12T06:16:47.857 回答
0
于 2013-03-12T05:56:41.737 回答
0

chiperteks你没有 给列名chiper db.execSQL("CREATE TABLE if not exists pesanKeluar (id_pk INTEGER PRIMARY KEY AUTOINCREMENT, nama TEXT, nomortlp TEXT, chiperteks TEXT);");

于 2013-03-12T05:56:54.527 回答
0

表 pesanKeluar 没有名为 chiper 的列

该错误表明您的所有表 pesanKeluar 都有一个列名chiperteks ...并且您正在提供要插入的密钥“chiper”。

于 2013-03-12T05:57:16.247 回答
0

插入 chiper=00010101 nama=D nomor=536 03-11 17:27:33.725: E/Database(1664): android.database.sqlite.SQLiteException: table pesanKeluar has no column named chiper: 时出错:编译时:INSERT INTO pesanKeluar (chiper, nama, nomor) 值(?, ?, ?);

当您的函数中的列与数据库中的列不同时会发生这种情况,请检查您的数据库是否chiper named colume存在或与您的数据库中的拼写相同?

您将列名定义为chiperteks在创建表时和插入数据时传递的错误为chiper,这会导致错误。

利用:

cv.put("chiperteks", k.getChiperteks());

反而:

cv.put("chiper", k.getChiperteks());

于 2013-03-12T05:57:43.397 回答
0

你有列名chiperteks但不在chiper你的表中pesanKeluar

代替

cv.put("chiper", k.getChiperteks());

cv.put("chiperteks", k.getChiperteks());
于 2013-03-12T05:58:58.020 回答
0

尝试这个

public void inputDataK(SQLiteDatabase db, pesanKeluar k) {
        ContentValues cv = new ContentValues();
        cv.put("nama", k.getNama());
        cv.put("nomortlp ", k.getNomorTlp()); // column name should be same as you define in Table
        cv.put("chiperteks ", k.getChiperteks());
        db.insert("pesanKeluar ", null, cv); 
        db.close();
    }
于 2013-03-12T06:00:57.553 回答