当前位置: 代码迷 >> Android >> Cursor 放在finilly中也关不掉 出错,闪退
  详细解决方案

Cursor 放在finilly中也关不掉 出错,闪退

热度:483   发布时间:2016-04-28 03:48:22.0
Cursor 放在finilly中也关不掉 报错,闪退
finally{
if(oCursorMood!=null){
  oCursorMood.close();//记得一定要关闭游标和数据库
  oCursorMood=null;
}
if(oCursorCMD!=null){
oCursorCMD.close();//关闭游标
oCursorCMD =null;
}
if (oClass!=null){
oClass.CloseDatabase();
oClass=null;
}
if (oDB!=null){ 
oDB.close();
oDB=null;
}
}




 Finalizing a Cursor that has not been deactivated or closed. database = /storage/emulated/0/SMART-BUS/Database.db3, table = mood_commands_of_room, query = SELECT CommandID, SequenceNo, SubnetID, DeviceID, CommandTypeID, FirstParameter, SecondParameter, ThirdParameter, DelayMillisecondAfterSend FROM mood_commands_of_room WHERE  RoomID=18 and MoodID=1 ORDER BY SequenceNO
 android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
  at android.database.sqlite.SQLiteCursor.<init>(SQLiteCursor.java:98)
  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:50)
  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1161)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1032)
  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1238)
  at caro.automation.room.mood_of_room.LoadDataFromDB(mood_of_room.java:314)
  at caro.automation.room.mood_of_room.onCreate(mood_of_room.java:238)
  at android.app.Activity.performCreate(Activity.java:5248)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
  at android.app.ActivityThread.startActivityNow(ActivityThread.java:2024)
  at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:135)
  at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:347)
  at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:749)
  at android.widget.TabHost.setCurrentTab(TabHost.java:413)
  at android.widget.TabHost.setCurrentTabByTag(TabHost.java:287)
  at caro.automation.room.room_control$3.onCheckedChanged(room_control.java:332)
  at android.widget.RadioGroup.setCheckedId(RadioGroup.java:174)
  at android.widget.RadioGroup.access$600(RadioGroup.java:54)
  at android.widget.RadioGroup$CheckedStateTracker.onCheckedChanged(RadioGroup.java:358)
  at android.widget.CompoundButton.setChecked(CompoundButton.java:130)
  at android.widget.CompoundButton.toggle(CompoundButton.java:87)
  at android.widget.RadioButton.toggle(RadioButton.java:76)
  at android.widget.CompoundButton.performClick(CompoundButton.java:99)
  at android.view.View$PerformClick.run(View.java:18440)
  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:5001)
  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:806)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:622)
  at dalvik.system.NativeStart.main(Native Method)

------解决思路----------------------
引用:
Quote: 引用:

Application did not close the cursor or database object that was opened here

并没有关闭cursor或者database,你把几个关闭的执行,debug一下.看是关哪个出的错.可能是关闭顺序的问题.


DeBug不出来, 一两次不会崩,就是退出再进去 可能就崩了。 debug的时候全都置为null了


我只能推测到这里了.debug不出,你可以在这此语句前加打印语句,哪个没执行到就是哪个出问题了.
  相关解决方案