- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
以下在数千台设备上运行,但最近我收到以下错误,两次,都是来自 android 6.0,所以它可能与新的 android 版本有关:
RootUtils.copyDatabase(path, pathApp);
if (new File(pathApp).exists())
{
L.d(this, "Database copied!"); // <= this is called, so copying file succeeds!!!
SQLiteDatabase db = SQLiteDatabase.openDatabase(pathApp, null, SQLiteDatabase.OPEN_READONLY);
final Cursor cursor = db.rawQuery("select * from contacts", new String[0]); // <= this line throws the exception
cursor.moveToFirst();
....
}
日志/异常
c.m.s.utils.RootUtils [RootUtils-91] copyDatabase: true
c.m.s.networks.utils.Util [FUtil-105] Database copied!
c.m.s.networks.utils.Util [FUtil-185] unknown error (code 14): Could not open database
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:191)
at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:806)
at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:791)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
...
我的复制功能如下:
public final static boolean copyDatabase(String pathSource, String pathTarget) throws IOException, InterruptedException, TimeoutException, RootDeniedException
{
Shell shell = RootTools.getShell(true);
Command command = new Command(0,
"su\n",
"rm " + pathTarget + "\n",
"cat " + pathSource + " > " + pathTarget + "\n",
"chown root.root " + pathTarget + "\n",
"chmod 777 " + pathTarget + "\n");
command = shell.add(command);
int exitCode = command.getExitCode();
while (!command.isFinished()) {
Thread.sleep(50);
}
shell.close();
boolean success = exitCode == -1 && command.isFinished();
L.d(RootUtils.class, "copyDatabase: " + success);
return success;
}
编辑:我的新复制功能甚至将 Owner/Group 设置为我的应用进程 - 目前只收到一个反馈,但似乎没有解决问题
public final static boolean copyDatabase(String ownAppDatabase, String pathSource, String pathTarget) throws IOException, InterruptedException, TimeoutException, RootDeniedException
{
Shell shell = RootTools.getShell(true);
boolean getRealUser = true;
String owner = null;
String group = null;
if (getRealUser)
{
final StringHolder lsResult = new StringHolder("");
Command lsCommand = new Command(0,
"su\n",
"ls -ld " + ownAppDatabase + "\n")
{
public void commandOutput(int id, String line) {
super.commandOutput(id, line);
lsResult.set(line);
}
};
lsCommand = shell.add(lsCommand);
int lsExitCode = lsCommand.getExitCode();
while (!lsCommand.isFinished()) {
Thread.sleep(50);
}
L.d(RootUtils.class, "ls exit code: " + lsExitCode);
L.d(RootUtils.class, "ls result: " + lsResult.get());
String[] parts = lsResult.get().split("\\s+");
if (parts.length > 3)
{
owner = parts[1];
group = parts[2];
}
}
if (owner == null || group == null)
{
L.d(RootUtils.class, "owner or group is NULL!");
getRealUser = false;
}
else
L.d(RootUtils.class, "owner=" + owner + " | group=" + group);
Command command = new Command(0,
"su\n",
"rm " + pathTarget + "\n",
"cat " + pathSource + " > " + pathTarget + "\n",
"chown " + (getRealUser ? (owner + "." + group + " ") : "chown root.root ") + pathTarget + "\n",
"chmod 777 " + pathTarget + "\n");
command = shell.add(command);
int exitCode = command.getExitCode();
while (!command.isFinished()) {
Thread.sleep(50);
}
shell.close();
boolean success = exitCode == -1 && command.isFinished();
L.d(RootUtils.class, "copyDatabase: " + success);
return success;
}
最佳答案
我在更新到 Android 6.0 后尝试打开存储在内部存储器上的 SQLite 数据库时遇到了同样的问题。
这是由 Marshmallow 的新权限模型引起的。
作为解决方法,我必须转到系统设置的我的应用程序的“应用程序信息”页面并授予存储访问权限。
关于android - SQLiteCantOpenDatabaseException => 未知错误(代码 14): Could not open database (Android 6. 0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33121097/
在 android 中使用 sqlite 数据库时,我遇到了一个奇怪的问题。我在表格中插入大约 500 个条目,但是当表格有大约 260-270 个条目时,它会显示此异常:
在我的应用程序中,我的 Assets 文件夹中有一个 SQLite 数据库的副本。据我所知,它工作正常。当我的应用程序第一次在我的模拟器中安装时,我收到如下错误: Failed to open the
在我的分析工具中,我可以看到 MD_LIFETAB_P9516 (Medion Lifetab) 有大量崩溃。它们因下面给出的堆栈跟踪而崩溃。 不过,其他任何设备都不会发生这种情况。在分析中,我可以看
我的应用程序已上线并从 Google Play 控制台收到“由:android.database.sqlite.SQLiteCantOpenDatabaseException:”引起的崩溃。 它主要发
我在打开 SQLite 数据库时遇到问题。它向我显示错误(代码 14)无法打开数据库。我已经尝试过针对先前提出的问题的解决方案,但没有帮助。我已经尝试检查数据库文件是否存在,我也添加了读写权限,但它仍
在我的内容提供者中,我创建并维护了 3 SQLiteDatabase对象。它们是这样创建的: private ContentProviderHelper helper; @Overri
当我尝试获取可读或可写的数据库时出现此错误。“SQLiteCantOpenDatabaseException:未知错误(代码 14)无法打开数据库”我在使用 SQLiteOpenHelper 时遇到了
我正在尝试从预构建数据库中打开文件。该数据库大约为 40-50 MB。我已经编写了将数据库从 Assets 复制到外部文件的代码。但是无法加载数据库。 我的数据库类 package com.examp
我在网站上阅读了有关此问题的各种内容,但我无法弄清楚这一点。我正在为此应用程序使用预构建数据库。我在这个应用程序中使用 jellybean。 AndroidManifest.xml
以下在数千台设备上运行,但最近我收到以下错误,两次,都是来自 android 6.0,所以它可能与新的 android 版本有关: RootUtils.copyDatabase(path, pathA
我已在网站上阅读了有关此问题的各种信息,但我无法弄清楚。我正在为此应用程序使用预构建数据库。我正在为这个应用程序使用 jellybean。 AndroidManifest.xml
所以我最近在我的应用程序中添加了持久性并且我得到了这个错误,有趣的部分是应用程序运行良好甚至持久化对象检索它们和所有但是在运行单元测试时我得到上面写的错误。 这是我的应用中有趣的部分 list 权限:
我正在尝试修复不允许我打开数据库的错误。可能通过所有合并,出了点问题,但我似乎找不到它。这是我的 Log Cat 报告。 E/SQLiteLog(894): (14) cannot open
我在网站上阅读了有关此问题的各种内容,但我无法弄清楚这一点。我被这一步卡住了好久。我该如何解决这个问题 Logcat 输出 根据logcat,这是由SQLiteCantOpenDatabaseExce
我是一名优秀的程序员,十分优秀!