Error while using sqlite in AsyncTask class in android?
<p>I got this error .. please help me to solve this error , or to know the reason !</p>

<pre><code>03-18 15:59:39.094: ERROR/AndroidRuntime(480): FATAL EXCEPTION: AsyncTask #2
03-18 15:59:39.094: ERROR/AndroidRuntime(480): java.lang.RuntimeException: An error occured while executing doInBackground()
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at android.os.AsyncTask$3.done(AsyncTask.java:200)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:274)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.FutureTask.setException(FutureTask.java:125)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.lang.Thread.run(Thread.java:1019)
03-18 15:59:39.094: ERROR/AndroidRuntime(480): Caused by: java.lang.IllegalStateException: database not open
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1146)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1422)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at aynoo.utility.DBAdapter.insertMessage(DBAdapter.java:67)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at aynoo.utility.Cach.AddMessages(Cach.java:23)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:396)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:1)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
03-18 15:59:39.094: ERROR/AndroidRuntime(480):     ... 4 more
03-18 15:59:39.484: ERROR/Database(480): close() was never explicitly called on database '/data/data/aynoo.forms/databases/aynoo' 
03-18 15:59:39.484: ERROR/Database(480): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
03-18 15:59:39.484: ERROR/Database(480):     at android.database.sqlite.SQLiteDatabase.&lt;init&gt;(SQLiteDatabase.java:1827)
03-18 15:59:39.484: ERROR/Database(480):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
03-18 15:59:39.484: ERROR/Database(480):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
03-18 15:59:39.484: ERROR/Database(480):     at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
03-18 15:59:39.484: ERROR/Database(480):     at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:541)
03-18 15:59:39.484: ERROR/Database(480):     at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
03-18 15:59:39.484: ERROR/Database(480):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
03-18 15:59:39.484: ERROR/Database(480):     at aynoo.utility.DBAdapter.open(DBAdapter.java:47)
03-18 15:59:39.484: ERROR/Database(480):     at aynoo.utility.Cach.AddMessages(Cach.java:22)
03-18 15:59:39.484: ERROR/Database(480):     at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:396)
03-18 15:59:39.484: ERROR/Database(480):     at aynoo.forms.FreindMessagesActivity$3$1RecentMessageLoader.doInBackground(FreindMessagesActivity.java:1)
03-18 15:59:39.484: ERROR/Database(480):     at android.os.AsyncTask$2.call(AsyncTask.java:185)
03-18 15:59:39.484: ERROR/Database(480):     at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
03-18 15:59:39.484: ERROR/Database(480):     at java.util.concurrent.FutureTask.run(FutureTask.java:138)
03-18 15:59:39.484: ERROR/Database(480):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
03-18 15:59:39.484: ERROR/Database(480):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
03-18 15:59:39.484: ERROR/Database(480):     at java.lang.Thread.run(Thread.java:1019)
</code></pre>

<p>where  Cach class is </p>

<pre><code>public class Cach {
    static DBAdapter db;
    public Cach(Context c)
    {
    }

    public static void AddMessages(Context c,
                                  int id,
                                  int fromId,
                                  int toId,
                                  String message,
                                  String dir,
                                  String MessageTime)
    {
        db = new DBAdapter(c);
        db.open();        
        db.insertMessage(id, fromId, toId, message, dir,MessageTime);
        db.close();
    }
}
</code></pre>
