我的应用程序中有一些代码,但是当我插入表格时出现错误。我不知道为什么。谁能帮我??
这是我的代码:
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;
}
}