2014-11-08 96 views
3

我得到這個錯誤,當應用程序崩潰我不明白這個錯誤這個錯誤說什麼。 這裏我把我的郵件崩潰日誌報告。下面檢查我所以下方法用於打開和關閉數據庫,我有定義2954行錯誤Sqlite數據庫Pragma異常?

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

嘗試寫'Open_Database()的UI層關閉數據庫; '和'Close_Database();'外部循環。 – 2014-11-08 12:33:07

回答

6

有在你的代碼基本缺陷。每當調用Open_Database時,覆蓋mDB_HelpermSQLiteDatabase。現在,當您調用Close_Database時,已經打開的連接會發生什麼情況。只有最後一個連接被關閉。

而是遵循Singleton模式有mDB_Helper

只是一個實例或更改代碼做開了,你在哪裏都使用DBConnection的

+0

你能告訴我需要做什麼改變嗎?我沒有得到你 – Mahesh 2014-11-08 13:45:05

+0

你可以按照這篇文章 - http://www.vogella.com/tutorials/AndroidSQLite/article.html – Aun 2014-11-08 13:57:24

+0

一個工作示例可能會有所幫助:http:///stackoverflow.com/a/19996964/197165 – HackNone 2016-01-23 12:18:05