1、如果是4.2的系统,则有可能是系统权限机制问题:
I faced this problem, it was because in 4.2, there is multi users support, and if you are testing with non-admin user, you cannot acess /data/data path..
In my case i’m using the path:
context.getFilesDir().getAbsolutePath().replace("files", "databases") + File.separator
http://androiddev.orkitra.com/?p=13793
就是说,androi4.2中引入了多用户机制,普通用户无法访问根目录下的/data/data目录,因而无法创建数据库文件。而我的安卓模拟器确实是最新的4.2版本,因此就会有这种问题。
知道原因就很好解决了,按照上面的方法使用context.getFilesDir().getAbsolutePath()获取绝对路径即可。
2、也有可能是路径问
比如,项目的MainActivity位于 com.example.finance.activity,而一般db的路径会设置为/data/data/com.example.finance/mydb。
这么写就会导致权限问题,所以其实应该是/data/data/com.example.finance.activity/mydb