在Android的恢复活动的SQLite异常 [英] SQLite Exception on Resuming Android Activity

查看:141
本文介绍了在Android的恢复活动的SQLite异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序有活动的层次,-launches- C A -launches-乙

在第三个活动'C'我有一个按钮。

在此按钮的onClickListener我发起的意图如下:

 意向意图=新的意图(Intent.ACTION_DIAL);
intent.setData(Uri.parse(URI));
startActivity(意向);
//我不叫面漆()
 

它带来了电话拨号对话框罚款。如果我打的后退按钮在这一点上,我得到了对不起!弹出说我的应用程序意外停止。在打强制关闭按钮,我的应用程序将恢复为活动'B'而不是预期的C(假设没有崩溃)。

活动'B'确实使用在异常显示,但是我不知道为什么它是当我打'回',因为它有无关的活动C导致异常的SQL查询。我的数据库已经关闭,我没有得到一个泄漏的警告。

在活动B打开数据库之前立即执行查询,并随后关闭。与此挣扎了一整天,以便将AP preciate任何意见。

 未捕获的处理程序:螺纹主力退出,由于未捕获的异常
 java.lang.IllegalStateException:mQuery选择islocal,包标识,名称,mapradius从类别中,islocal =? 1
     在android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:162)
     在android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:536)
     在android.app.Activity.performRestart(Activity.java:3740)
     在android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3312)
     在android.app.ActivityThread.access $ 2600(ActivityThread.java:123)
     在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1890)
     在android.os.Handler.dispatchMessage(Handler.java:99)
     在android.os.Looper.loop(Looper.java:123)
     在android.app.ActivityThread.main(ActivityThread.java:4370)
     在java.lang.reflect.Method.invokeNative(本机方法)
     在java.lang.reflect.Method.invoke(Method.java:521)
     在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:868)
     在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     在dalvik.system.NativeStart.main(本机方法)
 致:android.database.sqlite.SQLiteMisuseException:库函数叫了顺序:处理为0x0
     在android.database.sqlite.SQLiteProgram.native_bind_string(本机方法)
     在android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
     在android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:153)
     ... 13更多
ERROR / SemcCheckin(17282):获取崩溃转储级别:java.io.FileNotFoundException:/数据/ SEMC-签入/故障转储
 

解决方案

我刚刚解决了这个例外,在我的应用程序。不知道的原因是一样的你...

活动A的执行查询通过桥接表连接2数据库中的表。从这些记录联接放入一个ListView,当用户点击的记录,我的应用程序打完活动B.当你点击活动B上的后退按钮,恢复活动一此异常发生。

此修复程序是在活动一个明确关闭游标(cur.close()),当它完成检索数据。以前我只是关闭数据库。

这并没有发生,如果活动一做没有参加基本查询。如此看来,如果你加入多个表,并返回一个指针,该系统上的任务恢复时打开的游标进行重新查询生成此异常。你必须明确地关闭游标,这样的简历建立一个新的。这可能导致此的另一个因素是,在活动一我的数据库访问发生在一个单独的工作线程。

My app has a hierarchy of Activities, A -launches- B -launches- C

In the third Activity 'C' I have a button.

In the onClickListener of this button I launch an Intent as follows:

Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse(uri));
startActivity(intent);
//I don't call finish()

It brings up the phone dialling dialog fine. If I hit the back button at this point I get the "Sorry!" popup saying my app stopped unexpectedly. On hitting the "Force Close" button my app reverts to the Activity 'B' rather then the expected 'C' (Assuming no crash).

Activity 'B' does use the SQL query shown in the exception however I don't know why it is causing the exception when I hit 'Back' as it has nothing to do with Activity 'C'. My database has been closed and I don't get an Leak warnings.

In Activity 'B' the database is opened immediately prior to executing the query and closed afterward. Struggling with this all day so would appreciate any comments.

 Uncaught handler: thread main exiting due to uncaught exception
 java.lang.IllegalStateException: mQuery SELECT islocal, packageid, Name, mapradius FROM categories WHERE islocal=? 1 
     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:162)
     at android.database.sqlite.SQLiteCursor.requery(SQLiteCursor.java:536)
     at android.app.Activity.performRestart(Activity.java:3740)
     at android.app.ActivityThread.handleWindowVisibility(ActivityThread.java:3312)
     at android.app.ActivityThread.access$2600(ActivityThread.java:123)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1890)
     at android.os.Handler.dispatchMessage(Handler.java:99)
     at android.os.Looper.loop(Looper.java:123)
     at android.app.ActivityThread.main(ActivityThread.java:4370)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:521)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
     at dalvik.system.NativeStart.main(Native Method)
 Caused by: android.database.sqlite.SQLiteMisuseException: library routine called out of sequence: handle 0x0
     at android.database.sqlite.SQLiteProgram.native_bind_string(Native Method)
     at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:178)
     at android.database.sqlite.SQLiteQuery.requery(SQLiteQuery.java:153)
     ... 13 more
ERROR/SemcCheckin(17282): Get crash dump level : java.io.FileNotFoundException: /data/semc-checkin/crashdump

解决方案

I just solved this exception in my app. Not sure if the cause was the same as yours...

Activity A was performing a query JOIN on 2 tables in the database via a bridge table. The records from that join were put into a ListView and when a user clicks a record, my app fires off Activity B. When you hit the back button on Activity B, resuming Activity A this exception happened.

The fix was to explicitly close the cursor (cur.close()) in Activity A when it was finished retrieving data. Before I was just closing the DB.

This DID NOT happen if Activity A did a basic query without a JOIN. So it seems when you join multiple tables and return in a cursor, the requery that the system performs on that open cursor when your task resumes generates this exception. You have to explicitly close the cursor so that the resume establishes a new one. Another factor that could have caused this is that my DB access in Activity A happens on a separate worker thread.

这篇关于在Android的恢复活动的SQLite异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆