Sqlite数据库实用程序异常? [英] Exception For Sqlite Database Pragma?

查看:282
本文介绍了Sqlite数据库实用程序异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序崩溃时,我收到此错误,我不明白此错误说明了什么。
在这里,我从邮件中输入了崩溃日志报告。在下面检查我在以下用于打开和关闭数据库的方法中使用的方法:我为错误定义了2954行

I got this error when app was crashed i dont understand this error what this error said. here i put my crash log report from mail. check below for what i have used below method for open and close database i have define 2954 line for 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 ***


推荐答案

您的代码中存在基本缺陷。每次覆盖 Open_Database mDB_Helper mSQLiteDatabase 时叫。现在,当您调用Close_Database时,已经打开的连接将如何处理。仅最后一个连接被关闭。

there is basic flaw in your code. Every time you are overwriting mDB_Helper and mSQLiteDatabase when Open_Database is called. Now when you call Close_Database, what happens to already opened connections. only the last connection is closed.

遵循单例模式,只有一个 mDB_Helper

Instead follow singleton pattern have just one instance of mDB_Helper

或更改代码以在使用dbconnection的UI层中打开和关闭数据库

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

这篇关于Sqlite数据库实用程序异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆