Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.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 插入到MSQLite时出错_Android_Sqlite_Class - Fatal编程技术网

Android 插入到MSQLite时出错

Android 插入到MSQLite时出错,android,sqlite,class,Android,Sqlite,Class,我有以下代码从布局中的字段收集数据(同一类),并尝试将其放入msqlite数据库中: public void submitOrder(Order order_) { SQLiteDatabase db=DBHelper.getWritableDatabase(); ContentValues cv=new ContentValues(); cv.put(DatabaseHelper.colName, order_.name); cv.pu

我有以下代码从布局中的字段收集数据(同一类),并尝试将其放入msqlite数据库中:

public void submitOrder(Order order_) {
    SQLiteDatabase db=DBHelper.getWritableDatabase();
    ContentValues cv=new ContentValues();
        cv.put(DatabaseHelper.colName,      order_.name);
        cv.put(DatabaseHelper.colLink,      order_.link);
        cv.put(DatabaseHelper.colPrice,     order_.price);
        cv.put(DatabaseHelper.colDateYear,  order_.year);
        cv.put(DatabaseHelper.colDateMonth, order_.month);
        cv.put(DatabaseHelper.colDateDay,   order_.day);

        db.insert(DatabaseHelper.orderTable, null, cv);
    db.close();
我创建了MSQlite数据库助手类:

package com.Sagi.MyOrders;

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

public class DatabaseHelper extends SQLiteOpenHelper {

static final String dbName="DBname";
static final String orderTable="Orders";
static final String colName="OrderName";
static final String colLink="OrderLink";
static final String colDateYear="DateYear";
static final String colDateMonth="DateMonth";
static final String colDateDay="DateDay";
static final String colPrice="OrderPrice";
static String CREATE_T;

public DatabaseHelper(Context context) {
      super(context, dbName, null,1);
}
/** Called when the activity is first created. */
@Override
public void onCreate(SQLiteDatabase db) {
        CREATE_T="CREATE TABLE orderTable ("
                + "colName TEXT,"
                + "colLink TEXT,"
                + "colPrice TEXT,"
                + "colDateYear INTEGER,"
                + "colDateMonth INTEGER,"
                + "colDateDay INTEGER);";
        db.execSQL(CREATE_T);
        Log.e("Table creator","Table Created successfully");
     }
当我运行它并单击按钮将信息存储在数据库中时,我会收到一条错误消息:

06-02 06:19:43.454: E/Database(1570): android.database.sqlite.SQLiteException: table Orders has no column named OrderPrice: , while compiling: INSERT INTO Orders(DateDay, DateMonth, OrderLink, OrderName, OrderPrice, DateYear) VALUES(?, ?, ?, ?, ?, ?);
06-02 06:19:43.444: I/Database(1570): sqlite returned: error code = 1, msg = table Orders has no column named OrderPrice
以及一条I级消息:

06-02 06:19:43.454: E/Database(1570): android.database.sqlite.SQLiteException: table Orders has no column named OrderPrice: , while compiling: INSERT INTO Orders(DateDay, DateMonth, OrderLink, OrderName, OrderPrice, DateYear) VALUES(?, ?, ?, ?, ?, ?);
06-02 06:19:43.444: I/Database(1570): sqlite returned: error code = 1, msg = table Orders has no column named OrderPrice

希望你能帮忙。。。谢谢

它说
表Orders没有名为OrderPrice的列
。原因是您没有更新数据库。只需卸载/重新安装你的应用程序。一切都会好起来的

编辑后:

您可以使用创建表

CREATE_T="CREATE TABLE orderTable ("
                + "colName TEXT,"
                + "colLink TEXT,"
                + "colPrice TEXT,"
                + "colDateYear INTEGER,"
                + "colDateMonth INTEGER,"
                + "colDateDay INTEGER);";
        db.execSQL(CREATE_T);
这意味着您要创建一个名为
orderTable
的表

但在你的插页中:

public void submitOrder(Order order_) {
    SQLiteDatabase db=DBHelper.getWritableDatabase();
    ContentValues cv=new ContentValues();
        cv.put(DatabaseHelper.colName,      order_.name);
        cv.put(DatabaseHelper.colLink,      order_.link);
        cv.put(DatabaseHelper.colPrice,     order_.price);
        cv.put(DatabaseHelper.colDateYear,  order_.year);
        cv.put(DatabaseHelper.colDateMonth, order_.month);
        cv.put(DatabaseHelper.colDateDay,   order_.day);

        db.insert(DatabaseHelper.orderTable, null, cv); // This line
    db.close();
您使用的是
DatabaseHelper.orderTable
,它是
静态最终字符串orderTable=“Orders”;
它们不相等,因此出现此错误

更改orderTable变量或表名,就可以了


希望这有助于

清除数据或unistall应用程序,然后它会很好地工作,这似乎给了我另一个步骤,我现在得到以下错误:06-02 06:50:02.646:I/数据库(328):sqlite返回:错误代码=1,消息=没有这样的表:OrdersHanks。我已经看到,当我使用vars创建表列时,它处理得不是很好,所以我将其更改为Strings,现在一切都正常了。。糟糕的是,按字符串命名的列更有条理。