当应用程序崩溃时我收到此错误我不明白此错误所说的错误。 在这里我把邮件的崩溃日志报告。检查下面我使用下面的方法打开和关闭数据库我已经定义了2954行错误
private void Open_Database()
{
//this is 2954 line
mDB_Helper = new DB_Helper(this);
mSQLiteDatabase = mDB_Helper.getWritableDatabase();
}
/* Closing DB */
private void Close_Database()
{
if (mSQLiteDatabase != null && mDB_Helper != null)
{
mSQLiteDatabase.close();
mDB_Helper.close();
}
}
public void deletedata()
{
deleteplaylist.clear();
Open_Database();
deleteplaylist=new ArrayList<HashMap<String,String>>();
deleteplaylist=mDB_Helper.DeleteRecordDetail(mSQLiteDatabase, DB_Constant.TABLE.MYFILES,DB_Constant.MYFILES.USERID, sid);
Close_Database();
for(int m=0;m<deleteplaylist.size();m++)
{
String getid=deleteplaylist.get(m).get(DB_Constant.MYFILES.FILE_ID).toString();
String getpath=deleteplaylist.get(m).get(DB_Constant.MYFILES.FILE_PATH).toString();
Open_Database();
DB_Helper.DeleteData(mSQLiteDatabase, DB_Constant.TABLE.MYFILES,DB_Constant.MYFILES.USERID, sid,DB_Constant.MYFILES.FILE_ID,getid);
File file = new File(getpath);
boolean deleted = file.delete();
Close_Database();
}
}
2014-11-08-19-56-30
Yoddle
Error Report collected on : Sat Nov 08 19:56:30 GMT+08:00 2014
Informations :
Locale: en_US
Version: 1.0
Package: com.peak.media
Phone Model: NEO-X8-H
Android Version: 4.4.2
Board: NEO-X8
Brand: MINIX
Device: NEO-X8
Host: user-desktop
ID: KOT49H
Model: NEO-X8-H
Product: k200
Type: user
Total Internal memory: 13396525056
Available Internal memory: 11685687296
Stack:
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file (code 14): , while compiling: PRAGMA journal_mode
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:894)
at android.database.sqlite.SQLiteConnection.executeForString(SQLiteConnection.java:639)
at android.database.sqlite.SQLiteConnection.setJournalMode(SQLiteConnection.java:323)
at android.database.sqlite.SQLiteConnection.setWalModeFromConfiguration(SQLiteConnection.java:297)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:218)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:196)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:464)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:186)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:178)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:808)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:793)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:698)
at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:976)
at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:256)
at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:224)
at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
at com.peak.media.HomeActivityNewViewPager.Open_Database(HomeActivityNewViewPager.java:2954)
at com.peak.media.HomeActivityNewViewPager.deletedata(HomeActivityNewViewPager.java:3130)
at com.peak.media.HomeActivityNewViewPager$4.run(HomeActivityNewViewPager.java:800)
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:5017)
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:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
at dalvik.system.NativeStart.main(Native Method)
**** End of current Report ***
答案 0 :(得分:6)
您的代码存在基本缺陷。每当您在调用mDB_Helper
时覆盖mSQLiteDatabase
和Open_Database
时。现在,当您调用Close_Database时,已打开的连接会发生什么。只关闭最后一个连接。
相反,按照单身模式只有一个mDB_Helper
或更改代码以在您使用dbconnection的UI层中打开和关闭数据库