SQLiteDiskIOException:错误code 10:磁盘I / O错误 [英] SQLiteDiskIOException: error code 10: disk I/O error

查看:769
本文介绍了SQLiteDiskIOException:错误code 10:磁盘I / O错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我感动SQLite数据库到SD卡,但somtimes会抛出异常SQLiteDiskIOException:错误code 10:磁盘I / O错误

I moved sqlite database to sdcard,but somtimes will throw exception "SQLiteDiskIOException: error code 10: disk I/O error".

我怎样才能prevent这种事情发生。

How can I prevent this happen.

推荐答案

由于您使用外部存储,应用程序必须意识到外部存储状态,您可以通过`Environment.getExternalStorageState()获得的。

Since you are using External Storage, your application must be aware of the External Storage state, which you can get via `Environment.getExternalStorageState()'.

您只能访问外部存储时的状态是装式

You must only access External Storage when the state is MOUNTED.

如果你试图打开一个文件(或SQLite的数据库;!它只是一个文件)在设备启动时,你会肯定有问题的,因为外部存储的未安装直到进入设备启动(后显示主屏幕)。

If you are trying to open a file (or SQLite DB; it's just a file!) during device startup, you will definately have problems, because External Storage is not mounted until well into device startup (after Home Screen is displayed).

的出路,这是注册一个的IntentFilter 被通知在外部存储状态的所有变化,以及相应的行为。

The way out of this is to register an IntentFilter to be notified of all changes in External Storage state, and behave accordingly.

它总是阅读的文档是个好主意!看到Android文档的详细信息:<一href="http://developer.android.com/reference/android/os/Environment.html">http://developer.android.com/reference/android/os/Environment.html

It's always a good idea to read the documentation! See the Android documentation for details: http://developer.android.com/reference/android/os/Environment.html

使用外部存储用于此目的是可疑的,因为当它变得不可用,你无法控制!例如,用户插入其设备插入USB他们的计算机上,并选择启用USB大容量的选项,所以它们可以从他们的计算机上访问他们的装置的外部存储器。坏消息!您的应用程序将从外部存储器断开,并最有可能没有机会做任何的清理IO!

Using External Storage for this purpose is dubious, because you cannot control when it becomes unavailable! For example, the user plugs their device into USB on their computer, and selects the "Enable USB Mass Storage" option, so they can access their device's External Storage from their computer. Bad news! Your app will be disconnected from External Storage, and most-likely without the opportunity to do any clean-up IO!

通过这种状况,你现在只剩下如何处理你会投入你的数据库中的数据,只要它是可用的。

With this state of affairs, you are now left with What To Do with all the data you would be putting into your database, if only it were available.

这篇关于SQLiteDiskIOException:错误code 10:磁盘I / O错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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