带有错误代码10的SQLiteDiskIOException:磁盘I/O错误 [英] SQLiteDiskIOException with error code 10: disk I/O error

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

问题描述

我将SQLite数据库移至SD卡,但有时它将引发以下异常:

I moved an SQLite database to an SD card, but sometimes it will throw the following exception:

android.database.sqlite.SQLiteDiskIOException: error code 10: disk I/O error

关于如何防止这种情况发生的任何建议?

Any suggestions on how I can prevent this from happening?

推荐答案

由于您使用的是外部存储,因此您的应用程序必须知道可以通过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().

您只能在状态为MOUNTED时访问外部存储.

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

如果您在设备启动期间尝试打开文件(或SQLite DB;它只是一个文件!),您肯定会肯定遇到问题,因为外部存储未安装 strong>,直到设备启动(显示主屏幕后)为止.

If you are trying to open a file (or SQLite DB; it's just a file!) during device startup, you will definitely 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文档: 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.

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

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