package nidhin.survey;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DatabaseHelper extends SQLiteOpenHelper {
static final String TABLE = "mygrades";
static final String NAME = "name";
static final String VALUE1 = "value1";
static final String VALUE2 = "value2";
static final String VALUE3 = "value3";
static final String VALUE4 = "value4";
static final String VALUE5 = "value5";
static final String VALUE6 = "value6";
static final String VALUE7 = "value7";
static final String VALUE8 = "value8";
static final String VALUE9 = "value9";
static final String VALUE10 = "value10";
static final String VALUE11 = "value11";
DatabaseHelper(Context context)
{
super(context, "grades.sqlite", null, 1);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("CREATE TABLE " + TABLE + " (_id INTEGER PRIMARY KEY AUTOINCREMENT," +
VALUE1 + " TEXT, " + VALUE2 + " TEXT, " +VALUE3 + " TEXT, " + VALUE4 + " TEXT, " +VALUE5 + " TEXT, " +VALUE6 + " TEXT, " +VALUE7 + " TEXT, " +VALUE8 + " TEXT, " +VALUE9 + " TEXT, " +VALUE10 + " TEXT, " +
VALUE11 + " REAL);");
ContentValues cv = new ContentValues();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
// TODO Auto-generated method stub
android.util.Log.w("mygrades", "Upgrading database, this will destroy all data");
db.execSQL("DROP TABLE IF EXISTS " + TABLE);
onCreate(db);
}
}
我遇到問題(可能是語法問題)。我想在SQLite的幫助下在android中創建一個表。我有一個NAME列和VALUE1到VALUE11列。但是,當我嘗試運行代碼時,Logcat中出現以下錯誤:在Android中初始化表格時出現問題
03-30 02:38:16.593: E/AndroidRuntime(693): java.lang.RuntimeException: Unable to start activity ComponentInfo{nidhin.survey/nidhin.survey.Database}: android.database.sqlite.SQLiteException: no such column: value1: , while compiling: SELECT _id, name, value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11 FROM mygrades
任何想法?
請記錄onCreate的輸出字符串。 ... String s =「CREATE TABLE」+ TABLE +「(_id INTEGER PRIMARY KEY AUTOINCREMENT,」+ VALUE1 + ...; android.util.Log.d(「mygrades」,s); – 2012-03-30 03:10:05