我嘗試放入新數據時遇到問題。在數據庫上保存項目時出錯,android studio
我的代碼:
ThoughtManager:
public long createThought(Thought thought) // TWORZE NOWY ELEMENT W BAZIE DANYCH!!!
{
contentValues.put(ThoughtDbHelper.INDEXNUMBER, thought.getIndexNumber());
contentValues.put(ThoughtDbHelper.NAME, thought.getName());
contentValues.put(ThoughtDbHelper.TIME, thought.getTime());
contentValues.put(ThoughtDbHelper.DATE, thought.getDate());
contentValues.put(ThoughtDbHelper.GROUPCODE, thought.getGroupCode());
contentValues.put(ThoughtDbHelper.IDPRINTFINGER, thought.getIDPrintfinger());
contentValues.put(ThoughtDbHelper.AMOUNTOFPRESENCE, thought.getAmountOfPresence());
return db.insert(ThoughtDbHelper.TABLE_NAME, null, contentValues);
}
DbHelper:
//Zmienne do mojej bazy danych
static final String INDEXNUMBER="indexnumber";
static final String NAME="name";
static final String GROUPCODE="groupcode";
static final String IDPRINTFINGER="idprintfinger";
static final String KEY="_id";
static final String AMOUNTOFPRESENCE="amountofpresence";
static final String DATE="date";
static final String TIME="time";
static final String TABLE_NAME="thought_tbl";
static final String DATABASE_NAME="thought_db.sql"; // nasza baza danych
static final int DATABASE_VERSION = 1; // wesja naszej bazy danych
private String QUERY_STRING="CREATE TABLE " + TABLE_NAME + " ("+KEY
+ " INTEGER PRIMARY KEY AUTOINCREMENT , "+ INDEXNUMBER
+ " TEXT NOT NULL, " + NAME + " TEXT NOT NULL , " + TIME
+ " TEXT, " + DATE + " TEXT, " + GROUPCODE + " TEXT, " + IDPRINTFINGER
+ " TEXT, " + AMOUNTOFPRESENCE
+ " TEXT)";
而且階級梅託德當我嘗試添加新的數據:
case R.id.btnAddThought:
if(requestReply!=null)
{
idPrintfinger=requestReply;
}
index=etIndex.getText().toString(); // Pobieram z pola tekstowe wpisane znaki i zapisuje je do zmiennej
name=etName.getText().toString();
groupcode=etGroup.getText().toString();
thougt.setIndexNumber(index); // zapisuje w bazie poszczegolne elementy
thougt.setName(name);
thougt.setTime(time);
thougt.setDate(date);
thougt.setGroupCode(groupcode);
thougt.setIDPrintfinger(idPrintfinger);
thougt.setAmountOfPresence(amountOfPresence);
manager.openForWrite(); // właczma odpcje zpaisywania na DYSK!
long res=manager.createThought(thougt); // Zapisuje dane na DYSKU!
if(res!=-1)
{
ClearFields();
}
break;
這裏是我的編輯LogCat,仍然有問題,這個代碼的問題,我propably失明或某物
3-23 18:00:27.084 24591-24591/com.example.iorwet.thoghtaplication
E/SQLiteLog: (1) table thought_tbl has no column named groupcode
03-23 18:00:27.084 24591-24591/com.example.iorwet.thoghtaplication
E/SQLiteDatabase: Error inserting groupcode=dasdasdada indexnumber=asdasddsdasd time=00:00 amountofpresence=0 idprintfinger=000 date=01.01.1990 name=asdada
android.database.sqlite.SQLiteException: table thought_tbl has no column named groupcode (code 1): , while compiling: INSERT INTO thought_tbl(groupcode,indexnumber,time,amountofpresence,idprintfinger,date,name) VALUES (?,?,?,?,?,?,?)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
at com.example.iorwet.thoghtaplication.ThoughtManager.createThought(ThoughtManager.java:74)
at com.example.iorwet.thoghtaplication.AddThought.onClick(AddThought.java:138)
at android.view.View.performClick(View.java:4438)
at android.view.View$PerformClick.run(View.java:18422)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
我編輯我的代碼,我把錯誤的代碼放在ThoughtDbHelper中。你能再看看 – Iorwet
還是一樣的錯誤。您爲contentValues.put(ThoughtDbHelper.GROUP,think.getGroup())插入值;但你有專欄'組代碼' –
我改成我的代碼,但它不工作; /我有組代碼我都他們 – Iorwet