我在Android开发中作为编码员开始我的旅程。如果错误太简单,请原谅。 我正在面对我正在创建的SQLite数据库的问题,我无法解决它。
I/art: Background partial concurrent mark sweep GC freed 48228(1684KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/4MB, paused
6.769ms total 25.319ms I/art: Background sticky concurrent mark sweep GC freed 56325(1885KB) AllocSpace objects, 0(0B) LOS objects, 40% free, 2MB/4MB, paused 9.877ms total 33.077ms I/art: Background partial concurrent mark sweep GC freed 56480(1897KB) AllocSpace objects, 1(328KB) LOS objects, 40% free, 2MB/4MB, paused 10.284ms total
36.064ms I/art: Background sticky concurrent mark sweep GC freed 49608(1660KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/4MB, paused 13.506ms total 44.492ms I/art: Background partial concurrent mark sweep GC freed 49621(1661KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/4MB, paused 13.629ms total 49.390ms I/art: Background sticky concurrent mark sweep GC freed 49640(1662KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/4MB, paused
19.149ms total 54.527ms I/art: Background partial concurrent mark sweep GC freed 49720(1664KB) AllocSpace objects, 0(0B) LOS objects, 39% free, 2MB/4MB, paused 17.575ms total 56.892ms E/SQLiteConnection: sqlite3_close(0x7f3b5dd15280) failed: 5 E/SQLiteConnectionPool: Failed to close connection, its fate is now in the hands of the merciful GC: SQLiteConnection: /data/user/0/com.dankildev.mymedicationreminder/databases/medicine.db (0)
android.database.sqlite.SQLiteDatabaseLockedException: unable to close due to unfinalized statements or unfinished backups (code 5): Count not close db.
at android.database.sqlite.SQLiteConnection.nativeClose(Native Method)
at android.database.sqlite.SQLiteConnection.dispose(SQLiteConnection.java:238)
at android.database.sqlite.SQLiteConnection.close(SQLiteConnection.java:203)
at android.database.sqlite.SQLiteConnectionPool.closeConnectionAndLogExceptionsLocked(SQLiteConnectionPool.java:528)
at android.database.sqlite.SQLiteConnectionPool.closeAvailableConnectionsAndLogExceptionsLocked(SQLiteConnectionPool.java:501)
at android.database.sqlite.SQLiteConnectionPool.dispose(SQLiteConnectionPool.java:226)
at android.database.sqlite.SQLiteConnectionPool.close(SQLiteConnectionPool.java:205)
at android.database.sqlite.SQLiteDatabase.dispose(SQLiteDatabase.java:295)
at android.database.sqlite.SQLiteDatabase.onAllReferencesReleased(SQLiteDatabase.java:272)
at android.database.sqlite.SQLiteClosable.releaseReference(SQLiteClosable.java:74)
at android.database.sqlite.SQLiteClosable.close(SQLiteClosable.java:106)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:277)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
at com.dankildev.mymedicationreminder.addMedicineActivity.save(addMedicineActivity.java:145)
at com.dankildev.mymedicationreminder.addMedicineActivity.access$300(addMedicineActivity.java:26)
at com.dankildev.mymedicationreminder.addMedicineActivity$2.onClick(addMedicineActivity.java:100)
at android.view.View.performClick(View.java:5198)
at android.view.View$PerformClick.run(View.java:21147)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) D/AndroidRuntime: Shutting down VM I/art: Background sticky concurrent mark sweep GC freed 57379(9MB) AllocSpace objects, 12(6MB) LOS objects, 0% free, 34MB/34MB, paused 598us total 108.933ms W/SQLiteConnectionPool: A SQLiteConnection object for database '/data/user/0/com.dankildev.mymedicationreminder/databases/medicine.db' was leaked! Please fix your application to end transactions in progress properly and to close the database when it is no longer needed. E/SQLiteConnection: sqlite3_close(0x7f3b5dd15280) failed: 5 E/System: Uncaught exception thrown by finalizer E/System: android.database.sqlite.SQLiteDatabaseLockedException: unable to close due to unfinalized statements or unfinished backups (code 5): Count not close db.
at android.database.sqlite.SQLiteConnection.nativeClose(Native Method)
at android.database.sqlite.SQLiteConnection.dispose(SQLiteConnection.java:238)
at android.database.sqlite.SQLiteConnection.finalize(SQLiteConnection.java:178)
at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:202)
at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:185)
at java.lang.Thread.run(Thread.java:818) W/art: Suspending all threads took: 11.514ms I/art: Background sticky concurrent mark sweep GC freed 29721(4MB) AllocSpace objects, 0(0B) LOS objects, 0% free, 80MB/80MB, paused 11.913ms total 25.311ms E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.dankildev.mymedicationreminder, PID: 7791
java.lang.StackOverflowError: stack size 8MB
at java.lang.CaseMapper.toUpperCase(CaseMapper.java:147)
at java.lang.String.toUpperCase(String.java:1158)
at android.database.DatabaseUtils.getSqlStatementType(DatabaseUtils.java:1399)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:890)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
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.executeSql(SQLiteDatabase.java:1674)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:39)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLi D/Error: ERR: exClass=java.lang.StackOverflowError D/Error: ERR: exMsg=stack size 8MB D/Error: ERR: file=CaseMapper.java D/Error: ERR: class=java.lang.CaseMapper D/Error: ERR: method=toUpperCase line=147 W/art: Suspending all threads took: 17.524ms D/Error: ERR: stack=java.lang.StackOverflowError: stack size 8MB
at java.lang.CaseMapper.toUpperCase(CaseMapper.java:147)
at java.lang.String.toUpperCase(String.java:1158)
at android.database.DatabaseUtils.getSqlStatementType(DatabaseUtils.java:1399)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:890)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:498)
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.executeSql(SQLiteDatabase.java:1674)
at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:39)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicationreminder.DataBase.MedicineSQLiteHelper.onCreate(MedicineSQLiteHelper.java:40)
at com.dankildev.mymedicat D/Error: ERR: TOTAL BYTES WRITTEN: 16144400 E/JavaBinder: !!! FAILED BINDER TRANSACTION !!! (parcel size = 16144492) E/AndroidRuntime: Error reporting crash
android.os.TransactionTooLargeException: data parcel size 16144492 bytes
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:503)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4425)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:90)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
这是我尝试创建数据库并将数据添加到数据库表时出现的错误。 我运行的代码如下:
MedicineSQLiteHelper mMedicineSQLiteHelper = new MedicineSQLiteHelper(this);
SQLiteDatabase db = mMedicineSQLiteHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(MedEntry.COLUMN_MED_NAME, medicamentName);
values.put(MedEntry.COLUMN_DOSAGE, dosage);
values.put(MedEntry.COLUMN_ICON_ID, icon);
values.put(MedEntry.COLUMN_NUMBER_OF_HOURS, Integer.parseInt(numberOfHours));
values.put(MedEntry.COLUMN_HOURS_DAYS, hourDaySpinnerContent);
values.put(MedEntry.COLUMN_HOURS, hourSelected);
values.put(MedEntry.COLUMN_MINUTES, minuteSelected);
values.put(MedEntry.COLUMN_DAY, day);
values.put(MedEntry.COLUMN_MONTH, month);
values.put(MedEntry.COLUMN_YEAR, year);
long newRowId = db.insert(MedEntry.TABLE_NAME, null, values);
MedicineSQLiteHelper类如下:
public class MedicineSQLiteHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "medicine.db";
private static final int DB_VERSION = 1;
public MedicineSQLiteHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String SQL_CREATE_MEDS_TALBE = "CREATE TABLE IF NOT EXISTS " + MedEntry.TABLE_NAME + " ( "
+ MedEntry._ID + " INTEGER PRIMARY KEY, "
+ MedEntry.COLUMN_MED_NAME + " TEXT ,"
+ MedEntry.COLUMN_DOSAGE + " TEXT ,"
+ MedEntry.COLUMN_ICON_ID + " INTEGER ,"
+ MedEntry.COLUMN_NUMBER_OF_HOURS + " INTEGER ,"
+ MedEntry.COLUMN_HOURS_DAYS + " TEXT ,"
+ MedEntry.COLUMN_HOURS + " INTEGER ,"
+ MedEntry.COLUMN_MINUTES + " INTEGER ,"
+ MedEntry.COLUMN_DAY + " INTEGER ,"
+ MedEntry.COLUMN_MONTH + " INTEGER ,"
+ MedEntry.COLUMN_YEAR + " INTEGER );";
db.execSQL(SQL_CREATE_MEDS_TALBE);
onCreate(db);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
我的理解告诉我这是一个与未关闭游标有关的问题?
我希望我已经添加了所有必要的信息,如果有人为我提供了一些代码向我解释错误,我将非常感谢! :)