我的程序包含一个带有name= countable
. 首先它只包含 3 列并且它正在工作。然后我插入了一个countevent
以变量名KEY_EVENT命名的新列。然后>程序显示错误,因为列名countevent
不存在。请帮我找到一个>解决方案。
FirstActivity.java 包含以下代码。
class clicker implements Button.OnClickListener {
public void onClick(View v) {
String datevalue = date.getText().toString();
String Userselectvalue = userSelection.getText().toString();
String Userevent = edittext.getText().toString();
SQLiteDatabase db = eventsData.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(classdbOpenHelper.KEY_DESC, Userselectvalue);
cv.put(classdbOpenHelper.KEY_EVENT, Userevent);
cv.put(classdbOpenHelper.KEY_DATE,datevalue);
db.insert(classdbOpenHelper.DATABASE_TABLE, null, cv);
db.close();
类dbOpenHelper
package example.showevent1;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.TextView;
public class classdbOpenHelper extends SQLiteOpenHelper {
public static final String KEY_ROWID = "_id";
public static final String KEY_DESC = "countdesc";
public static final String KEY_EVENT = "countevent";
public static final String KEY_DATE = "countdate";
public static final String DATABASE_NAME= "countdb";
public static final String DATABASE_TABLE = "countable";
public static final int DATABASE_VERSION = 1;
public classdbOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
/* db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT " +
//KEY_COUNTED + " INTEGER " +
KEY_DESC + " TEXT NOT NULL " +
KEY_DATE + " TEXT NOT NULL);"
); */
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + DATABASE_TABLE + "("
+ KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT " + KEY_DESC + " TEXT " + KEY_EVENT + " TEXT " + KEY_DATE + " TEXT " + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXITS " + DATABASE_TABLE);
onCreate(db);
}
String getContact() {
SQLiteDatabase db = this.getReadableDatabase();
int _id = 0;
Cursor cursor = db.query(DATABASE_TABLE , new String[] { KEY_ROWID,
KEY_DESC,KEY_EVENT, KEY_DATE}, KEY_ROWID + "=?",
new String[] { String.valueOf(_id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
String place = cursor.getString( cursor.getColumnIndex("KEY_EVENT"));
return place;
}
}
登录
08-05 07:43:26.918: E/SQLiteLog(838): (1) table countable has no column named countevent
08-05 07:43:26.978: E/SQLiteDatabase(838): Error inserting countdesc=Yalahanka countevent=hh countdate=8-5-2013
08-05 07:43:26.978: E/SQLiteDatabase(838): android.database.sqlite.SQLiteException: table countable has no column named countevent (code 1): , while compiling: INSERT INTO countable(countdesc,countevent,countdate) VALUES (?,?,?)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
08-05 07:43:26.978: E/SQLiteDatabase(838): at example.showevent1.FirstActivity$clicker.onClick(FirstActivity.java:148)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.view.View.performClick(View.java:4204)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.view.View$PerformClick.run(View.java:17355)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.os.Handler.handleCallback(Handler.java:725)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.os.Handler.dispatchMessage(Handler.java:92)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.os.Looper.loop(Looper.java:137)
08-05 07:43:26.978: E/SQLiteDatabase(838): at android.app.ActivityThread.main(ActivityThread.java:5041)
08-05 07:43:26.978: E/SQLiteDatabase(838): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 07:43:26.978: E/SQLiteDatabase(838): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 07:43:26.978: E/SQLiteDatabase(838): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
08-05 07:43:26.978: E/SQLiteDatabase(838): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
08-05 07:43:26.978: E/SQLiteDatabase(838): at dalvik.system.NativeStart.main(Native Method)