오류 :안드로이드 SQLite 데이터베이스를 만들 수 없습니다 : PRAGMA 오류
E/Database(8614): Failure 21 (out of memory) on 0x0 when preparing 'PRAGMA user_version = 1'.
E/Database(8614): Failure 21 (out of memory) on 0x0 when preparing 'ROLLBACK;'.
D/Database(8614): exception during rollback, maybe the DB previously performed an auto-rollback
D/AndroidRuntime(8614): Shutting down VM
W/dalvikvm(8614): threadid=3: thread exiting with uncaught exception (group=0x4001dc20)
E/AndroidRuntime(8614): Uncaught handler: thread main exiting due to uncaught exception
내 현재 코드 :
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper {
private static String DatabaseName = "Entries.db";
public Database(Context context) {
super(context, DatabaseName, null, 1);
}
public void onCreate(SQLiteDatabase D) {
D.execSQL(
"CREATE TABLE Containers ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "Parent INTEGER,"
+ "Sequence INTEGER,"
+ "Name TEXT"
+ ")"
);
D.execSQL(
"CREATE TABLE Files ("
+ "ID INTEGER PRIMARY KEY AUTOINCREMENT,"
+ "Parent INTEGER,"
+ "Sequence INTEGER,"
+ "Name TEXT,"
+ "Text TEXT"
+ ")"
);
D.execSQL("INSERT INTO Containers (Parent, Sequence, Name) VALUES (0, 2, \"TestLine2\")");
D.execSQL("INSERT INTO Containers (Parent, Sequence, Name) VALUES (0, 1, \"TestLine1\")");
D.execSQL("INSERT INTO Containers (Parent, Sequence, Name) VALUES (0, 3, \"TestLine3\")");
D.execSQL("INSERT INTO Containers (Parent, Sequence, Name) VALUES (2, 1, \"TestLine2-1\")");
D.execSQL("INSERT INTO Containers (Parent, Sequence, Name) VALUES (2, 2, \"TestLine2-2\")");
D.close();
}
@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
}
public static Cursor Query(Context context, String SQL) {
StartQuerySeries(context);
Cursor Result = Query(SQL);
StopQuerySeries();
return Result;
}
private static Database D = null;
public static void StartQuerySeries(Context context) {
D = new Database(context);
}
public static Cursor Query(String SQL) {
SQLiteDatabase X = D.getWritableDatabase();
return X.rawQuery(SQL, null);
}
public static void StopQuerySeries() {
D.close();
D = null;
}
}
기본 활동에,이 같이라고 할 때, 오류가 발생
:
Database.Query(this, "INSERT INTO Files (Parent, Sequence, Name, Text) VALUES (1, 1, \"Item1\", \"Item1 Text\")");
"D.getWritableDatabase()"줄에 오류가 발생했습니다 ... 내가 가장 가까이에있는 것은에 있습니다.실패 21에 "라이브러리가 잘못 사용되었습니다"라는 메시지가 나타납니다 - 어떤 도움이 필요합니까?
오, 내가 확인 - 데이터베이스 파일이 생성되지만 거기에 테이블이 없으므로 위에서 onCreate()가 호출되지 않습니다.
나는 "onCreate()"에서 하나를 제거한 후 2 개의'D.close()'줄을 발견했다. 감사! – Izkata
이 동작에 대한 설명은 http://stackoverflow.com/questions/5324241/what-happens-to-sqlitedatabase-object-which-is-passed-to-oncreate-method를 참조하십시오. – Chris