나는 다른 활동에서 내 데이터베이스를 호출하는 응용 프로그램을 만들고 있지만 데이터베이스 측면에서 모든 종류의 오류가 계속 발생합니다. 처음에는 "SQLiteException 같은 데이터가 없습니다"및 내 응용 프로그램을 삭제하고 다시 설치할 때 해당 지금 "android.database.sqlite.SQLiteConstraintException : 오류 코드 19 : 제약 조건이 실패했습니다".안드로이드 데이터베이스 문제
나는 무엇을 더 이상 할 생각이 없습니다. 데이터베이스 작성에 너무 많은 다른 예를 겪었지만 내가 뭔가를 놓친 거지 나도 몰라 .. 여기에 데이터베이스 측에 내 코드입니다 : 주요 오류 출력이 여기에있다
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DBAdapter {
private static final String DATABASE_NAME = "MemoData.db";
private static final int DATABASE_VERSION = 1;
public static final String DATABASE_TABLE = "Memo";
public static final String KEY_ID = "_id";
public static final String NAME = "Title";
public static final String START_DATE = "start_date";
public static final String END_DATE = "end_date";
public static final String NOTES = "notes";
private static final String TAG = "DBAdapter";
private static final String DATABASE_CREATE = "create table Memo (_id integer primary key autoincrement,"
+ "Title text not null, start_date text not null,"
+ "end_date text not null, "
+ "notes text not null);";
private final Context context;
private DBHelper dbhelper;
private SQLiteDatabase db;
public DBAdapter(Context context) {
this.context = context;
dbhelper = new DBHelper(context);
}
private static class DBHelper extends SQLiteOpenHelper {
DBHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG,"upgrading Database from version"+ oldVersion+ "to"
+newVersion+ "which oold data will be lost");
db.execSQL("DROP TABLE IF EXITS Memo");
onCreate(db);
}
}
public DBAdapter open()throws SQLException {
db = dbhelper.getWritableDatabase();
return this;
}
public void close(){
dbhelper.close();
}
public long createItem(String Title, String start_date,String end_date,String notes){
open();
ContentValues initialValues = new ContentValues();
initialValues.put(NAME, Title);
initialValues.put(START_DATE, start_date);
initialValues.put(END_DATE, end_date);
initialValues.put(NOTES, notes);
return db.insert(DATABASE_TABLE, null, initialValues);
}
public Cursor retrieveItems(){
SQLiteDatabase db = dbhelper.getWritableDatabase();
String[] resultColumns = new String[] {NAME,START_DATE,END_DATE,NOTES };
Cursor cursor = db.query(DATABASE_TABLE, resultColumns, null, null, null, null, null);
Integer cindex = cursor.getColumnIndex("Title");
String result = "Result = ";
if(cursor.moveToFirst()){
do {
result += cursor.getString(cindex)+ "-";
}while(cursor.moveToNext());
}
return cursor;
}
}
과 :
08-23 오류/데이터베이스 (775) : 메모 삽입 오류 = 참고 : end_date = 기한 = 항목 이름 : start_date = 시작 날짜 : 08-23 22 : 38 : 17.104 : 오류/데이터베이스 (775) : android.database.sqlite.SQLiteConstraintException : 오류 코드 19 : 제약 조건이 실패했습니다.
08-23 22 : 38 : 17.104 : ERROR/Database (775) : android.database.sqlite.SQL iteStatement.native_execute (기본 방법)
08-23 22 : 38 : 17.104 : ERROR/데이터베이스 (775) : android.database.sqlite.SQLiteStatement.execute (SQLiteStatement.java:66)에서
08- 23 : 38 : 17.104 : 오류/데이터베이스 (775) : android.database.sqlite.SQLiteDatabase.insertWithOnConflict (SQLiteDatabase.java:1313)
08-23 22 : 38 : 17.104 : ERROR/Database (775) : android.database.sqlite.SQLiteDatabase.insert (SQLiteDatabase.java:1173)
08-23 22 : 38 : 17.104 : ERROR/Database (775) : com.Memo.DBAdapter.createItem (DBAdapter.createItem) : 94)
08-23 22 : 38 : 17.104 : ERROR/데이터베이스 (775) : com.Memo.NewItem.save (NewItem.java:365) 당신의 onUpgrade 이벤트에서
이 코드 블록에서 이중 간격을 수정하십시오. 이것은 읽을 수 없습니다. – EboMike