"Unable to re-open an already closed object", when reading data from sqlite android -


itemprop = "text">

In my Android app, I am using SQLite database but when I use a query to read data from SQLite So, I get an error. This is my code to create the table.

  package com.example.mydb; Public class Dbadapter {Private static final string DATABASE_NAME = "mydb"; Personal Static FINAL END DATABASE_VERSION = 5; Private static final string DATABASE_TABLE18 = "modalation_medicine_table"; Private static final string MOD_ID = "modalation_previousss_id"; Private static final string MOD_MED_ID = "modalation_medicine_id"; Private static final string MOD_MEDICINE = "modalation_medicine"; Private static final String CREATE_DATABASE_TABLE18 = "Table does not exist to create" + DATABASE_TABLEl8 + "(" + MOD_MED_ID + "integer primary key autoincrement," + MOD_MEDICINE + "text" + MOD_ID + "integer" + "foreign key ( '+ MOD_ID + ") reference" "+ DATABASE_TABLE5 +" ( "+ MODALATION_KEY_ID +));"; private DbHelper our Heller; private final terms of our model, private SQLiteDatabase ourDatabase; private static class DbHelper SQLiteOpenHelper {public DbHelper (references) {max ( Reference, DATABASE_NAME, blank, DATABASE_VERSION) extends; // Tudo Auto-Generated Console Trctor stub} @ Override public Whaid on Create (SQLiteDatabase db) {db.execSQL (CREATE_DATABASE_TABLE18); materials price modalation_medicine = new content value (); Modalation_medicine.put (MOD_MEDICINE, "Ntrram Muriyatikm"); Modalation_medicine.put (MOD_ID, 1 ); Db.insert (DATABASE_TABLE18, tap, modalation_medicine); Modalation_medicine.put (MOD_MEDICINE, "Kalivera carbonica"); Modalation_medicine.put (MOD_ID, 1); Db.insert (DATABASE_TABLE18, tap, modalation_medicine); Modalation_medicine.put (MOD_MEDICINE, "Phosphorus"); Modalation_medicine.put (MOD_ID, 1); Db.insert (DATABASE_TABLE18, faucet, modalation_medicine); } @Override public void onUpgrade (SQLiteDatabase db, int oldVersion, integer NewVersion) {// TODO Auto-generated method stub db.execSQL ( "drop table if one exists" + DATABASE_TABLE18); }} Public Dbadapter (reference c) {ourContext = c; } Public Dbadapter throws open () SQLException {ourHelper = new DBHelper (ourContext); OurDatabase = ourHelper.getWritableDatabase (); This return; } Public Zero Closure () {ourHelper.close (); }  

Now, when my method is using this method to read the data from sqlite db, then give me an error "unable to open the previously closed object again"

  public boolean mod_app_symps (string l, string modfinalMed) {String [] modalation = new string [] {MOD_ID, MOD_MEDICINE}; Cursor C24; Boolean iscontain = false; C24 = ourDatabase.query (DATABASE_TABLE18, modalation, "modalation_previousss_id = and modalation_medicine =?", New String [] {L, modfinalMed}, null, null, null); If (c24.getCount ()> gt; {iscontain = true; } Return iscontain; }  

I tried to solve this problem through Google but did not help anything! PS: I have read many other ways that are doing the same thing from I SQLite db, and all of these work fine. The error is only coming to this method.

Edit: This method works well

  public string [] getmodMed (long L) {string [] modalation_med = new string [] {MOD_ID, MOD_MEDICINE} ; Cursor C19 = ourDatabase.query (DATABASE_TABLE18, modalation_med, MOD_ID + '=' + + + l + "'', zero, null, null, null); String mod_medicine [] = new string [c19.getCount ()]; Int Imodedicine = C19 .get Cologum Index (MOD_medicin); If (c19! = Null) {c19.moveToFirst (); While (! C19.isAfterLast ()) {for (int i = 0; i & lt; c19.getcount (); i ++) {mod_medicine [i] = c19.getString (emod medicine); C19.moveToNext (); }}} Return mod_medicine; }  

This is caused by this line of code:

  Public Zero Closure () {ourHelper.close (); }  

You close a database and then want to log in again.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -