Exception for Sqlite Database Pragma?

I got this error when the application was crashed. I don't understand this error what this error was talking about. here i put my crash log report from mail. check below that i used below method for open and close database. I have defined line 2954 for the error.

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 ***

      

+3


source to share


1 answer


there is a major flaw in the code. Every time you call mDB_Helper

and mSQLiteDatabase

when you call Open_Database

. Now when you call Close_Database, what happens to the already open connections. only the last connection is closed.

Instead, it follows that a singleton template has only one instance mDB_Helper



or change the code to open and close the database in the UI layer where ever you use dbconnection

+6


source







All Articles