Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/220.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 错误插入“;没有列“;_Android_Sqlite - Fatal编程技术网

Android 错误插入“;没有列“;

Android 错误插入“;没有列“;,android,sqlite,Android,Sqlite,我的应用程序中有一些代码,但是当我插入一个表时,我得到了一个错误。我 不知道为什么。有人能帮我吗 这是我的代码: protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tambahpenerima); data = new dbHelper(this); db = data.getWritab

我的应用程序中有一些代码,但是当我插入一个表时,我得到了一个错误。我 不知道为什么。有人能帮我吗

这是我的代码:

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;
}

}

“没有列”错误明确指出,该列不在您指定的表中。所以,要么您引用了错误的表,要么您的列名拼写错误。在您的情况下,列名拼写错误。创建表时,您将第四列命名为
chiperteks
,将数据插入此列时,您将其称为
chiper
,这是完全错误的

更改如下,然后它将开始工作

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

您已经给出了coulmn名称
chiperteks
not
chiper
db.execSQL(“如果不存在,则创建表pesanKeluar(id_pk INTEGER主键自动递增,nama文本,nomortlp文本,chiperteks文本)”

表pesanKeluar没有名为chiper的列

错误显示所有表pesanKeluar都有一个列名chiperteks。。。你给了一个钥匙“切屑器”来插入

插入chiper=0000101 nama=D nomor=536 03-11 17:27:33.725:E/数据库(1664):android.Database.sqlite.SQLiteException:表pesanKeluar没有名为chiper:的列,编译时出错:插入pesanKeluar(chiper,nama,nomor)值(?,,?)

当函数中的列与数据库中的列不相同时发生此错误,请检查数据库中是否存在名为Colum的
chiper
,或者是否存在与数据库中相同的拼写

创建表时将列名定义为
chiperteks
,插入数据时错误地将列名定义为
chiper
,这会导致错误

使用:

cv.put(“chiperteks”,k.getChiperteks())

相反:

cv.put(“chiper”,k.getChiperteks())


您的表中有列名
chiperteks
,但没有
chiper

替换

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

试试这个

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();
    }

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

我已将chiper更改为chiperteks,但我遇到了相同的错误。还有其他解决方案吗?然后交叉检查表是否已创建?并将表列与插入函数进行比较。我已经尝试过这样做,但还是像以前一样出现了相同的错误。我真的不知道为什么。你能帮我吗?@niaa,我看到了,但我想这行代码是hasil=paket.getString(“chiper”)也需要相同的更改。如何清除数据?我不知道我的数据库位置在哪里。我已在“文件浏览”上搜索,但未找到。请转到“设置”>>“应用”>>“选择应用名称”>>详细信息您可以选择清除数据。
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();
    }