I am getting the exception log as
11-23 11:25:56.110: E/Database(543): Error inserting PartyCode=PM001 PaymentMode=0 Amount=12.2 ReceiptDate=1353522600000 SalesmanCode=SL1
11-23 11:25:56.110: E/Database(543): android.database.sqlite.SQLiteException: error code 5: database is locked
11-23 11:25:56.110: E/Database(543): at android.database.sqlite.SQLiteStatement.native_execute(Native Method)
11-23 11:25:56.110: E/Database(543): at android.database.sqlite.SQLiteStatement.execute(SQLiteStatement.java:55)
11-23 11:25:56.110: E/Database(543): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1549)
11-23 11:25:56.110: E/Database(543): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
11-23 11:25:56.110: E/Database(543): at com.virtuosoitech.dsr.dataaccess.ReceiptDataManager.insertNewReceipt(ReceiptDataManager.java:244)
11-23 11:25:56.110: E/Database(543): at com.virtuosoitech.dsr.ui.GlobalSalesReportOpt.onDestroy(GlobalSalesReportOpt.java:1460)
11-23 11:25:56.110: E/Database(543): at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3642)
11-23 11:25:56.110: E/Database(543): at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3673)
11-23 11:25:56.110: E/Database(543): at android.app.ActivityThread.access$2900(ActivityThread.java:125)
11-23 11:25:56.110: E/Database(543): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
11-23 11:25:56.110: E/Database(543): at android.os.Handler.dispatchMessage(Handler.java:99)
11-23 11:25:56.110: E/Database(543): at android.os.Looper.loop(Looper.java:123)
11-23 11:25:56.110: E/Database(543): at android.app.ActivityThread.main(ActivityThread.java:4627)
11-23 11:25:56.110: E/Database(543): at java.lang.reflect.Method.invokeNative(Native Method)
11-23 11:25:56.110: E/Database(543): at java.lang.reflect.Method.invoke(Method.java:521)
11-23 11:25:56.110: E/Database(543): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-23 11:25:56.110: E/Database(543): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-23 11:25:56.110: E/Database(543): at dalvik.system.NativeStart.main(Native Method)
while cancelling execution of the asynktask and trying to insert the new entry in the database
class HttpTask extends AsyncTask<String, Void, SalesDetails> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
spinningDialog = new ProgressDialog(GlobalSalesReportOpt.this);
spinningDialog.setMessage("Please wait..");
spinningDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
spinningDialog.setCancelable(true);
spinningDialog.show();
}
@Override
protected SalesDetails doInBackground(
String... params) {
// TODO Auto-generated method stub
ArrayList<InvoiceBrand> invoice_data_brandList = (ArrayList<InvoiceBrand>) SalesDataManager
.getInstance().getOptimizedSalesData(
getApplicationContext(), group, party, item,
company, brand, family, datefrom, dateTo);
}
@Override
protected void onPostExecute(SalesDetails details) {
// TODO Auto-generated method stub
Log.e("GlobalSalesReport", "onCancelled()");
uiStartTime = new Date().getTime();
if (spinningDialog == null) {
return;
}
spinningDialog.dismiss();
spinningDialog = null;
}
and my sample DB class for insertion is as
public long insertNewReceipt(Context context, Receipt receipt) {
SQLiteOpenHelper helper = null;
SQLiteDatabase db = null;
long orderId = 0;
try {
helper = new DSRDBHelper(context);
db = helper.getWritableDatabase();
ContentValues receiptValues = new ContentValues();
receiptValues.put("ReceiptDate", Util.getDate(receipt.getReceiptDate()).getTime());
if (receipt.getPaymentMode() == Constants.CASH_TYPE){
receiptValues.put("PaymentMode", Constants.CASH_TYPE);
}
else if (receipt.getPaymentMode() == Constants.CHEQUE_TYPE){
receiptValues.put("PaymentMode", Constants.CHEQUE_TYPE);
receiptValues.put("ChqueDate", receipt.getChequeDate());
receiptValues.put("ChqueNo", receipt.getChequeNo());
receiptValues.put("BankName", receipt.getBankName());
}
receiptValues.put("Amount", receipt.getAmount());
receiptValues.put("PartyCode", receipt.getPartyCode());
receiptValues.put("SalesmanCode", receipt.getSalesmanCode());
orderId = db.insert("Receipt", null, receiptValues);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
if (helper != null) {
helper.close();
}
if (db != null) {
db.close();
}
}
return orderId;
}
So please help me in solve this problem.. I have tried using singleton pattern for DB helper but it couldnt helped me... And is my DB class is violating general practices(should i use content provider instead??).. If yes the provide me the links regarding..