Please Help!!! error Leak Found: IllegalStateException

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Please Help!!! error Leak Found: IllegalStateException

Postby dreamdelerium » Sun Jan 31, 2010 7:03 pm

Someone please help me with this! When my application is started, i want to create a database, if it doesnt already exist. Here is my code, found in OnCreate:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. SQLiteDatabase myDB = null;
  5.  
  6. try {
  7.  
  8.      this.openOrCreateDatabase(MY_DATABASE_NAME, 0, null);
  9.  
  10. //Where MY_DATABASE_NAME is name of db
  11.  
  12.      myDB = this.openOrCreateDatabase(MY_DATABASE_NAME, 0, null);
  13.  
  14.   myDB.close
  15.  
  16. }
  17.  
  18. catch (IllegalStateException e){
  19.  
  20.         myDB.close();
  21.  
  22.        
  23.  
  24.         System.out.println( e.getMessage());
  25.  
  26. }
  27.  
  28.  
  29.  
  30. finally {
  31.  
  32.      if (myDB != null)
  33.  
  34.           myDB.close();
  35.  
  36. }
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


when i use the adb tool, i can see that the table has been created but in the logCat i get this error:
01-30 13:00:27.050: ERROR/Database(594): Leak found
01-30 13:00:27.050: ERROR/Database(594): java.lang.IllegalStateException: /data/data/com.SelectThree/databases/dbSelectThree.db SQLiteDatabase created and never closed
01-30 13:00:27.050: ERROR/Database(594): at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1694)
01-30 13:00:27.050: ERROR/Database(594): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)
01-30 13:00:27.050: ERROR/Database(594): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)
01-30 13:00:27.050: ERROR/Database(594): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
01-30 13:00:27.050: ERROR/Database(594): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
01-30 13:00:27.050: ERROR/Database(594): at com.SelectThree.SelectThree.onCreate(SelectThree.java:48)
01-30 13:00:27.050: ERROR/Database(594): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2444)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2497)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1848)
01-30 13:00:27.050: ERROR/Database(594): at android.os.Handler.dispatchMessage(Handler.java:99)
01-30 13:00:27.050: ERROR/Database(594): at android.os.Looper.loop(Looper.java:123)
01-30 13:00:27.050: ERROR/Database(594): at android.app.ActivityThread.main(ActivityThread.java:4338)
01-30 13:00:27.050: ERROR/Database(594): at java.lang.reflect.Method.invokeNative(Native Method)
01-30 13:00:27.050: ERROR/Database(594): at java.lang.reflect.Method.invoke(Method.java:521)
01-30 13:00:27.050: ERROR/Database(594): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-30 13:00:27.050: ERROR/Database(594): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-30 13:00:27.050: ERROR/Database(594): at dalvik.system.NativeStart.main(Native Method)

I get this error everytime i start the app, even if the db has been created previously. Ive tried catching the error, but nothing. The program still runs fine, the db is created. should i just ignore it (doesnt sound like a good idea to me)?
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

Postby BUKsAPPs » Sun Jan 31, 2010 7:48 pm

It looks like the first line in your try block isn't necessary. You are opening(or creating) the database, but not stroing the DB that is returned so you can close it later. Then the next line opens again, storing the DB that is returned. Just call "openOrCreateDatabase(...)" ONE time and set myDB equal to the return. Then you probably only need to call myDB.close in the finally block, not in all 3 sections.
BUKsAPPs
Experienced Developer
Experienced Developer
 
Posts: 71
Joined: Sat Jan 16, 2010 9:01 pm
Location: USA

Thanks!

Postby dreamdelerium » Sun Jan 31, 2010 8:29 pm

thanks you very much. i just removed :
this.openOrCreateDatabase(MY_DATABASE_NAME, 0, null);
and it now seems to work.
dreamdelerium
Developer
Developer
 
Posts: 30
Joined: Fri Jan 01, 2010 11:19 pm

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests