我在下面的课程中尝试在sqlite表中放入4列。在更改之前我有3列,一切都很好。添加4列名为COL5 = trasa的字符串看起来像:“Wiejska 14 | Leszczynowa 2 | Honoriusza Balzaka 11 | Honoriusza Balzaka 4 | Honoriusza Balzaka 1A |”工作室告诉我奇怪的错误。我不明白出了什么问题......
04-22 10:56:15.503 19238-19238 / com.example.norbert.routespreparation2 E / SQLiteLog:(1)表tabela_tras没有名为trasa的列
04-22 10:56:15.505 19238-19238 / com.example.norbert.routespreparation2 E / SQLiteDatabase:插入开始时出错= Wiejska 14 trasa = Wiejska 14 | Leszczynowa 2 | Honoriusza Balzaka 11 | Honoriusza Balzaka 4 | Honoriusza Balzaka 1A | koniec = Honoriusza Balzaka 1A czas = 0.43 KM AVS:151 KM / H时间:00:00:10
android.database.sqlite.SQLiteException:table tabela_tras没有名为trasa的列(代码1):,编译时:INSERT INTO tabela_tras(start,trasa,koniec,czas)VALUES(?,?,?,?)
在android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
在android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
在android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
在android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)
在android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31)
在android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1469)
在android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1341)
at com.example.norbert.routespreparation2.DatabaseHelper.addData(DatabaseHelper.java:86)
在com.example.norbert.routespreparation2.MapsActivity.butStop(MapsActivity.java:142)
at com.example.norbert.routespreparation2.MapsActivity_ViewBinding $ 1.doClick(MapsActivity_ViewBinding.java:37)
在butterknife.internal.DebouncingOnClickListener.onClick(DebouncingOnClickListener.java:22)
在android.view.View.performClick(View.java:4780)
在android.view.View $ PerformClick.run(View.java:19866)
在android.os.Handler.handleCallback(Handler.java:739)
在android.os.Handler.dispatchMessage(Handler.java:95)
在android.os.Looper.loop(Looper.java:135)
在android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
在java.lang.reflect.Method.invoke(Method.java:372)
在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:903)
在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
和班级:
class DatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "DatabaseHelper";
private static final String TABLE_NAME = "tabela_tras";
private static final String COL1 = "ID";
private static final String COL2 = "start";
private static final String COL3 = "koniec";
private static final String COL4 = "czas";
private static final String COL5 = "trasa";
public String getStartP() {
return StartP;
}
public void setStartP(String startP) {
StartP = startP;
}
public String getKoniecP() {
return KoniecP;
}
public void setKoniecP(String koniecP) {
KoniecP = koniecP;
}
public String getCzasP() {
return CzasP;
}
public void setCzasP(String czasP) {
CzasP = czasP;
}
public String StartP, KoniecP, CzasP, TrasaP;
public String getTrasaP() {
return TrasaP;
}
public void setTrasaP(String trasaP) {
TrasaP = trasaP;
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, "
+ COL2 + " TEXT," + COL3 + " TEXT," + COL4 + " TEXT," + COL5 + " TEXT)";
sqLiteDatabase.execSQL(createTable);
}
public DatabaseHelper(Context context) {
super(context, TABLE_NAME, null, 1);
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
sqLiteDatabase.execSQL("DROP IF TABLE EXIST " + TABLE_NAME);
onCreate(sqLiteDatabase);
}
public boolean addData() {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COL2, getStartP());
contentValues.put(DatabaseHelper.COL3, getKoniecP());
contentValues.put(DatabaseHelper.COL4, getCzasP());
contentValues.put(DatabaseHelper.COL5, getTrasaP());
long result = db.insert(TABLE_NAME, null, contentValues);
if (result == -1) {
return false;
} else {
return true;
}
}
public Cursor getData() {
SQLiteDatabase db = this.getWritableDatabase();
String query = "SELECT * FROM " + TABLE_NAME;
Cursor data = db.rawQuery(query, null);
return data;
}
}