- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
当我尝试获取可读或可写的数据库时出现此错误。“SQLiteCantOpenDatabaseException:未知错误(代码 14)无法打开数据库”我在使用 SQLiteOpenHelper 时遇到了这个奇怪的问题,我在这里看到了一些关于同一问题的类似答案,但没有一个解决了我的问题。和我一样绝望,我在下面发布我的代码,希望有人能找到我没有看到的东西......
(一个重要的信息:我从另一个工作的应用程序中得到这个应用程序。但是我第一次调试它时,我仍然没有更改 dbname。这是以前的应用程序的名称(ks.db)。该数据库存在于我的调试设备中,但 tr.db 不存在)
我的 DatabaseHelper 类是这样的:
//Singleton
private static DatabaseHelper sInstance;
//Log
private static String TAG = "Database";
private static final String NAME_DB = "tr.db";
private static final String PATH_DB_DEBUG = "/mnt/sdcard/";
private static final int VERSION = 4;
//TABLE NAMES
private static final String TABLE_USERS = "users";
private static final String TABLE_TRACKS = "tracks";
private static final String TABLE_ROTAS = "rotas";
...
/**
*
* @param context
* @return Unique instance of DataBaseHelper
*/
public static synchronized DatabaseHelper getInstance(Context context) {
if (sInstance == null) {
sInstance = new DatabaseHelper(context.getApplicationContext());
}
return sInstance;
}
我的安卓 list :
...
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
在主要 Activity 中:
//DB
DatabaseHelper database;
...
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
//database
database = DatabaseHelper.getInstance(this.getApplicationContext());
database.getReadableDatabase(); ( <- Error HERE)
这是完整的错误堆栈:
> 12-13 15:02:43.798 5764-5764/com.snitram.toriders E/SQLiteLog﹕ (14)
> cannot open file at line 31307 of [2ef4f3a5b1] 12-13 15:02:43.798
> 5764-5764/com.snitram.toriders E/SQLiteLog﹕ (14) os_unix.c:31307: (2)
> open(/storage/emulated/0tr.db) - 12-13 15:02:43.811
> 5764-5764/com.snitram.toriders E/SQLiteDatabase﹕ Failed to open
> database '/storage/emulated/0tr.db'.
> 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.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:571)
> at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)
> at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
> at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
> at com.snitram.toriders.activities.LoginActivity.onCreate(LoginActivity.java:222)
> at android.app.Activity.performCreate(Activity.java:6245)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
> at android.app.ActivityThread.-wrap11(ActivityThread.java)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 12-13
> 15:02:43.814 5764-5764/com.snitram.toriders E/SQLiteOpenHelper﹕
> Couldn't open /storage/emulated/0tr.db for writing (will try
> read-only):
> 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.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:571)
> at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:269)
> at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:223)
> at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
> at com.snitram.toriders.activities.LoginActivity.onCreate(LoginActivity.java:222)
> at android.app.Activity.performCreate(Activity.java:6245)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
> at android.app.ActivityThread.-wrap11(ActivityThread.java)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 12-13
> 15:02:43.815 5764-5764/com.snitram.toriders E/SQLiteLog﹕ (14)
> cannot open file at line 31307 of [2ef4f3a5b1] 12-13 15:02:43.815
> 5764-5764/com.snitram.toriders E/SQLiteLog﹕ (14) os_unix.c:31307: (2)
> open(/storage/emulated/0tr.db) - 12-13 15:02:43.816
> 5764-5764/com.snitram.toriders E/SQLiteDatabase﹕ Failed to open
> database '/storage/emulated/0tr.db'.
> 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.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:234)
> at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
> at com.snitram.toriders.activities.LoginActivity.onCreate(LoginActivity.java:222)
> at android.app.Activity.performCreate(Activity.java:6245)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
> at android.app.ActivityThread.-wrap11(ActivityThread.java)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 12-13
> 15:02:43.816 5764-5764/com.snitram.toriders D/AndroidRuntime﹕
> Shutting down VM 12-13 15:02:43.817 5764-5764/com.snitram.toriders
> E/AndroidRuntime﹕ FATAL EXCEPTION: main
> Process: com.snitram.toriders, PID: 5764
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.snitram.toriders/com.snitram.toriders.activities.LoginActivity}:
> android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error
> (code 14): Could not open database
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2426)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
> at android.app.ActivityThread.-wrap11(ActivityThread.java)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
> Caused by: 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.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:234)
> at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
> at com.snitram.toriders.activities.LoginActivity.onCreate(LoginActivity.java:222)
> at android.app.Activity.performCreate(Activity.java:6245)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1130)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2379)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2490)
> at android.app.ActivityThread.-wrap11(ActivityThread.java)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:148)
> at android.app.ActivityThread.main(ActivityThread.java:5443)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
最佳答案
您在可能不存在的文件路径上使用 SQLiteDatabase.openDatabase
。在 SQLiteDatabase.openDatabase
调用之前添加以下 2 行
private boolean checkDataBase() {
SQLiteDatabase checkDB = null;
try {
String myPath = DB_PATH + DB_NAME;
File file = new File(myPath);
if (file.exists() && !file.isDirectory())
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
} catch (SQLiteException e) {
// database does't exist yet.
}
if (checkDB != null) {
checkDB.close();
}
return checkDB != null ? true : false;
}
关于android - SQLiteCantOpenDatabaseException : unknown error (code 14) Could not open database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34253785/
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这是我的代码 14 20 {"Confirm Email"} 21 在第 17 行我得到错误 Type '{ pathname: string; user: { em
这个问题已经有答案了: How do I compare strings in Java? (23 个回答) 已关闭 8 年前。 为什么 KeyEvent.getKeyText(0).substrin
我正在尝试 Rust 的新 wasm32-unknown-unknown 目标,我在调用数学函数(例如 sin、cos、exp、atan2)时遇到问题。 cargo .toml: [package]
当我为 spring-boot 创建启动项目时,我在 pom 文件中收到此错误。这只是为了创建一个基本的 Spring Boot 项目 Project build error: Invalid pac
我已经订阅了我想要传输的数据。但不知何故它不起作用。我收到此错误: The property pipe is not available for type "OperatorFunction" 这是我
运行以下查询时。select * from surgerys where to_char(dt_surgery ,'DD-MM-YYYY' ) = to_char('12-02-2012','DD-M
我在运行存储过程时遇到以下异常: com.microsoft.sqlserver.jdbc.SQLServerException:不支持从 UNKNOWN 到 UNKNOWN 的转换。 过程定义如下:
我尝试运行以下代码。顺便说一句,我对 python 和 sklearn 都是新手。 import pandas as pd import numpy as np from sklearn.linear
我已经阅读了关于未知类型的官方文档,但我很难真正理解它是如何工作的。 人们可以在文档中读到:“在没有首先断言或缩小到更具体的类型之前,不允许对未知进行任何操作。” 但如果我有这个功能: const f
我正在尝试在Mac OS中设置Hadoop 2.6.0 我正在关注这篇文章: http://hadoop.apache.org/docs/r2.4.0/hadoop-project-dist/hado
配置 Nexus docker 注册表和代理“dockerhub-proxy”后,如下所述: https://help.sonatype.com/repomanager3/formats/docker
我收到此错误 - “ValueError:未知标签类型:'unknown'” 我已经在网上搜索但无法摆脱这个错误,顺便说一句,我是 python 的新手:) 我的数据有 5 行 22 列,最后一列是标
使用 SHA256 摘要标识符 拉取图像失败 最佳答案 不幸的是,这是 DockerHub 删除 Docker 1.9 守护进程的向后兼容性的副作用。当使用 Docker 1.10 推送图像时,较旧的
我是 postgresql 的新手,正在尝试使用全文搜索 to_tsvector但是我遇到了错误。 SQL 和错误 SELECT to_tsvector('english', 'The quick b
每当我这样做时 npm run watch ,第一次编译工作正常 - 但经过几次编译后,我最终会得到这个错误: 95% emitting unnamed compat pluginError: UNK
在一个新的 Angular 应用程序中,我收到以下错误:Error from chokidar : Error: UNKNOWN: unknown error, watch我已经删除并重新安装 nod
使用 Typescipt 4.x.x 我写了一些代码来实现其他语言 Elm/Rust/Haskell 中常用的 Maybe/Option 类型。 我想写一个可以接受映射类型的通用函数 type MyM
const submitted = useSelector((state) => state.post.submitted) 对于上面的状态。我得到错误: (参数)状态:未知对象的类型为“未知”。 这
我正在尝试将多架构 docker 镜像推送到 docker hub 并遇到错误(在 https://github.com/docker/distribution/issues/3100 处打开了 do
我是一名优秀的程序员,十分优秀!