android.database.sqlite。SQLiteException:表数据没有名为_Y的列。

时间:2021-01-04 23:01:57

I have a problem using my database. Please check this:

我的数据库有问题。请检查:

// Database Name
private static final String DATABASE_NAME = "Poloha";

// Data table name
private static final String DATA = "Data";

// Data Table Columns names
private static final String KEY_Y= "Y";
private static final String KEY_X= "X";
private static final String KEY_ID = "_id";
private static final String KEY_NAZEV = "Nazev";
private static final String KEY_MAC = "MAC";

public void onCreate(SQLiteDatabase db) 
{
    String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS" 
            + DATA + "("
            + KEY_ID + " INTEGER PRIMARY KEY autoincrement,"
            + KEY_NAZEV + " TEXT NOT NULL,"
            + KEY_MAC + " TEXT NOT NULL," 
            + KEY_X + " TEXT NOT NULL," 
            + KEY_Y + " TEXT NOT NULL);" ;
    db.execSQL(CREATE_CONTACTS_TABLE);
}

Now I want to add some values using:

现在我要添加一些值:

db.pridejZaznam(new Data(1,1,1,"NAZEV_1","MAC_1"));
db.pridejZaznam(new Data(2,2,2,"NAZEV_2","MAC_2"));
db.pridejZaznam(new Data(3,3,3,"NAZEV_3","MAC_3"));
db.pridejZaznam(new Data(4,4,4,"NAZEV_4","MAC_4"));

Problem is, LogCat is showing me this error:

问题是,LogCat向我展示了这个错误:

02-22 10:33:26.336: E/SQLiteLog(813): (1) table Data has no column named Y
02-22 10:33:26.375: E/SQLiteDatabase(813): Error inserting Y=1 MAC=MAC_1 Nazev=NAZEV_1 _id=1 X=1
02-22 10:33:26.375: E/SQLiteDatabase(813): android.database.sqlite.SQLiteException: table Data has no column named Y (code 1): , while compiling: INSERT INTO Data(Y,MAC,Nazev,_id,X) VALUES (?,?,?,?,?)

Any idea what should I do? I´ve check similar errors and found only a solution with a missing SPACE while creating table but if I´m not blind, I have it without anything missing. Thanks all :)

你知道我该怎么做吗?我检查了类似的错误,在创建表时,只找到了一个缺少空间的解决方案,但是如果我不是盲目的,我没有遗漏任何东西。感谢所有:)

4 个解决方案

#1


5  

public void onCreate(SQLiteDatabase db) 
{
    String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS" 
            + DATA + "("
            + KEY_ID + " INTEGER PRIMARY KEY," // and auto increment will be handled with                            primary key
            + KEY_NAZEV + " TEXT NOT NULL,"
            + KEY_MAC + " TEXT NOT NULL," 
            + KEY_X + " TEXT NOT NULL," 
            + KEY_Y + " TEXT NOT NULL);";
    db.execSQL(CREATE_CONTACTS_TABLE);
}

#2


1  

you dont need to add KEY_ID, database will add it automatically, remove first value from your insert query :

您不需要添加KEY_ID,数据库将自动添加它,从插入查询中删除第一个值:

db.pridejZaznam(new Data(1,1,"NAZEV_1","MAC_1"));

db。pridejZaznam(新数据(1,1,“NAZEV_1”、“MAC_1”));

and so on..

等等. .

and use english names for methods and variables for better underdstanding

使用英文名称来表示方法和变量,以便更好地理解。

#3


1  

You need space between the keyword EXISTS and the table name here:

在关键字和表名之间需要空格:

String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS" 
        + DATA + "("

change to:

改变:

String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS " 
        + DATA + "("

After editing the table schema, uninstall your app so the onCreate() gets run again. See also: When is SQLiteOpenHelper onCreate() / onUpgrade() run?

编辑表模式之后,卸载您的应用程序,以便onCreate()再次运行。参见:SQLiteOpenHelper onCreate() / onUpgrade()何时运行?

#4


0  

Just remove the app and install it again.

只需删除应用程序并重新安装它。

The MYSQLite table is stored in the local device and it does not append the tables

MYSQLite表存储在本地设备中,不附加表。

#1


5  

public void onCreate(SQLiteDatabase db) 
{
    String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS" 
            + DATA + "("
            + KEY_ID + " INTEGER PRIMARY KEY," // and auto increment will be handled with                            primary key
            + KEY_NAZEV + " TEXT NOT NULL,"
            + KEY_MAC + " TEXT NOT NULL," 
            + KEY_X + " TEXT NOT NULL," 
            + KEY_Y + " TEXT NOT NULL);";
    db.execSQL(CREATE_CONTACTS_TABLE);
}

#2


1  

you dont need to add KEY_ID, database will add it automatically, remove first value from your insert query :

您不需要添加KEY_ID,数据库将自动添加它,从插入查询中删除第一个值:

db.pridejZaznam(new Data(1,1,"NAZEV_1","MAC_1"));

db。pridejZaznam(新数据(1,1,“NAZEV_1”、“MAC_1”));

and so on..

等等. .

and use english names for methods and variables for better underdstanding

使用英文名称来表示方法和变量,以便更好地理解。

#3


1  

You need space between the keyword EXISTS and the table name here:

在关键字和表名之间需要空格:

String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS" 
        + DATA + "("

change to:

改变:

String CREATE_CONTACTS_TABLE = "CREATE TABLE IF NOT EXISTS " 
        + DATA + "("

After editing the table schema, uninstall your app so the onCreate() gets run again. See also: When is SQLiteOpenHelper onCreate() / onUpgrade() run?

编辑表模式之后,卸载您的应用程序,以便onCreate()再次运行。参见:SQLiteOpenHelper onCreate() / onUpgrade()何时运行?

#4


0  

Just remove the app and install it again.

只需删除应用程序并重新安装它。

The MYSQLite table is stored in the local device and it does not append the tables

MYSQLite表存储在本地设备中,不附加表。