- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在网站上阅读了有关此问题的各种内容,但我无法弄清楚这一点。我正在为此应用程序使用预构建数据库。我在这个应用程序中使用 jellybean。
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.quotes"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.quotes.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Logcat 输出
根据logcat,这是由SQLiteCantOpenDatabaseException引起的
06-10 23:07:01.831: E/Trace(4419): error opening trace file: No such file or directory (2)
06-10 23:07:03.611: E/SQLiteLog(4419): (14) cannot open file at line 30176 of [00bb9c9ce4]
06-10 23:07:03.621: E/SQLiteLog(4419): (14) os_unix.c:30176: (2) open(/data/data/com.example.quotes/databasesQuotesdb) -
06-10 23:07:03.641: E/SQLiteDatabase(4419): Failed to open database '/data/data/com.example.quotes/databasesQuotesdb'.
06-10 23:07:03.641: E/SQLiteDatabase(4419): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at com.example.quotes.DataBaseHelper.checkDataBase(DataBaseHelper.java:94)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at com.example.quotes.DataBaseHelper.createDataBase(DataBaseHelper.java:58)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at com.example.quotes.MainActivity.onCreate(MainActivity.java:34)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.Activity.performCreate(Activity.java:5104)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.os.Looper.loop(Looper.java:137)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-10 23:07:03.641: E/SQLiteDatabase(4419): at dalvik.system.NativeStart.main(Native Method)
06-10 23:07:03.731: E/SQLiteLog(4419): (14) cannot open file at line 30176 of [00bb9c9ce4]
06-10 23:07:03.731: E/SQLiteLog(4419): (14) os_unix.c:30176: (2) open(/data/data/com.example.quotes/databasesQuotesdb) -
06-10 23:07:03.781: E/SQLiteDatabase(4419): Failed to open database '/data/data/com.example.quotes/databasesQuotesdb'.
06-10 23:07:03.781: E/SQLiteDatabase(4419): android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at com.example.quotes.DataBaseHelper.openDataBase(DataBaseHelper.java:145)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at com.example.quotes.MainActivity.onCreate(MainActivity.java:44)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.Activity.performCreate(Activity.java:5104)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.os.Looper.loop(Looper.java:137)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-10 23:07:03.781: E/SQLiteDatabase(4419): at dalvik.system.NativeStart.main(Native Method)
06-10 23:07:03.791: D/AndroidRuntime(4419): Shutting down VM
06-10 23:07:03.791: W/dalvikvm(4419): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
06-10 23:07:03.831: E/AndroidRuntime(4419): FATAL EXCEPTION: main
06-10 23:07:03.831: E/AndroidRuntime(4419): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.quotes/com.example.quotes.MainActivity}: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread.access$600(ActivityThread.java:141)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.os.Looper.loop(Looper.java:137)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-10 23:07:03.831: E/AndroidRuntime(4419): at java.lang.reflect.Method.invokeNative(Native Method)
06-10 23:07:03.831: E/AndroidRuntime(4419): at java.lang.reflect.Method.invoke(Method.java:511)
06-10 23:07:03.831: E/AndroidRuntime(4419): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-10 23:07:03.831: E/AndroidRuntime(4419): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-10 23:07:03.831: E/AndroidRuntime(4419): at dalvik.system.NativeStart.main(Native Method)
06-10 23:07:03.831: E/AndroidRuntime(4419): Caused by: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:209)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:193)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:463)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:185)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:177)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:804)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:789)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:694)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:669)
06-10 23:07:03.831: E/AndroidRuntime(4419): at com.example.quotes.DataBaseHelper.openDataBase(DataBaseHelper.java:145)
06-10 23:07:03.831: E/AndroidRuntime(4419): at com.example.quotes.MainActivity.onCreate(MainActivity.java:44)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.Activity.performCreate(Activity.java:5104)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
06-10 23:07:03.831: E/AndroidRuntime(4419): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
06-10 23:07:03.831: E/AndroidRuntime(4419): ... 11 more
06-10 23:07:04.083: D/dalvikvm(4419): GC_CONCURRENT freed 203K, 11% free 2676K/3000K, paused 25ms+18ms, total 306ms
06-10 23:07:07.811: I/Process(4419): Sending signal. PID: 4419 SIG: 9
DataBaseHelper.java
public class DataBaseHelper extends SQLiteOpenHelper{
//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/com.example.quotes/databases";
private static String DB_NAME = "Quotesdb";
// Table Names of Data Base.
static final String TABLE_Name = "Quotes";
// Contacts Table Columns names
//private static final String _Id = "_Id";
//private static final String quotes = "quotes";
//private static final String author = "author";
private SQLiteDatabase myDataBase;
private final Context myContext;
/**
* Constructor
* Takes and keeps a reference of the passed context in order to access to the application assets and resources.
* @param context
*/
public DataBaseHelper(Context context) {
super(context, DB_NAME, null, 1);
this.myContext = context;
}
/**
* Creates a empty database on the system and rewrites it with your own database.
* */
public void createDataBase() throws IOException{
boolean dbExist = checkDataBase();
SQLiteDatabase db_Read = null;
if(dbExist){
//do nothing - database already exist
}else{
//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.
db_Read = this.getReadableDatabase();
db_Read.close();
try {
copyDataBase();
} catch (IOException e) {
//throw new Error("Error copying database");
e.toString();
}
}
}
/**
* Check if the database already exist to avoid re-copying the file each time you open the application.
* @return true if it exists, false if it doesn't
*/
private boolean checkDataBase(){
SQLiteDatabase checkDB = null;
try{
String myPath = DB_PATH + DB_NAME;
checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}catch(SQLiteException e){
//database does't exist yet.
}
if(checkDB != null){
checkDB.close();
}
return checkDB != null ? true : false;
}
/**
* Copies your database from your local assets-folder to the just created empty database in the
* system folder, from where it can be accessed and handled.
* This is done by transfering bytestream.
* */
private void copyDataBase() throws IOException{
//Open your local db as the input stream
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
}
public void openDataBase() throws SQLException{
//Open the database
String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
}
@Override
public synchronized void close() {
if(myDataBase != null)
myDataBase.close();
super.close();
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
/*// Getting single contact
public List<Quotes> getQuote(int id) {
ArrayList<Quotes>();
getReadableDatabase();
Cursor cursor = db.query(TABLE_Name, new String[] { _Id,
qotes,author }, _Id + "=?", new String[] { String.valueOf(id) },
null, null, null, null);
//String query = "SELECT _Id, qotes, author From "+TABLE_Name;
//String query = "SELECT * From Quotes";
//Cursor cursor = db.rawQuery(query, null);
if (cursor != null)
cursor.moveToFirst();
Quotes quotes = new Quotes(Integer.parseInt(cursor.getString(0)),
cursor.getString(1),cursor.getString(2));
QuoteList.add(quotes);
return QuoteList;
}
*/
}
最佳答案
将此权限添加到项目的 AndroidManifest.xml
文件中的 manifest
标记(应该是顶级标记)中。
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
关于android.database.sqlite.SQLiteCantOpenDatabaseException : unknown error (code 14): Could not open database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58855993/
reqwest v0.9 将 serde v1.0 作为依赖项,因此实现 converting serde_json errors into reqwest error . 在我的代码中,我使用 se
我有这个代码: let file = FileStorage { // ... }; file.write("Test", bytes.as_ref()) .map_err(|e| Mu
我只是尝试用angular-cli创建一个新项目,然后运行服务器,但是它停止并显示一条有趣的消息:Error: No errors。 我以这种方式更新了(希望有帮助):npm uninstall -g
我从我的 javascript 发送交易 Metamask 打开传输对话框 我确定 i get an error message in metamask (inpage.js:1 MetaMask -
这个问题在这里已经有了答案: How do you define custom `Error` types in Rust? (3 个答案) How to get a reference to a
我想知道两者之间有什么大的区别 if let error = error{} vs if error != nil?或者只是人们的不同之处,比如他们如何用代码表达自己? 例如,如果我使用这段代码: u
当我尝试发送超过 50KB 的图像时,我在 Blazor 服务器应用程序上收到以下错误消息 Error: Connection disconnected with error 'Error: Serv
我有一个error-page指令,它将所有异常重定向到错误显示页面 我的web.xml: [...] java.lang.Exception /vi
我有这样的对象: address: { "phone" : 888, "value" : 12 } 在 WHERE 中我需要通过 address.value 查找对象,但是在 SQL 中有函数
每次我尝试编译我的代码时,我都会遇到大量错误。这不是我的代码的问题,因为它在另一台计算机上工作得很好。我尝试重新安装和修复,但这没有帮助。这是整个错误消息: 1>------ Build starte
在我的代码的类部分,如果我写一个错误,则在不应该的情况下,将有几行报告为错误。我将'| error'放在可以从错误中恢复的良好/安全位置,但是我认为它没有使用它。也许它试图在某个地方恢复中间表情? 有
我遇到了 csv 输入文件整体读取故障的问题,我可以通过在 read_csv 函数中添加 "error_bad_lines=False" 来删除这些问题来解决这个问题。 但是我需要报告这些造成问题的文
在 Spring 中,验证后我们在 controller 中得到一个 BindingResult 对象。 很简单,如果我收到验证错误,我想重新显示我的表单,并在每个受影响的字段上方显示错误消息。 因此
我不知道出了什么问题,因为我用 Java 编程了大约一年,从来没有遇到过这个错误。在一分钟前在 Eclipse 中编译和运行工作,现在我得到这个错误: #A fatal error has been
SELECT to_char(messages. TIME, 'YYYY/MM/DD') AS FullDate, to_char(messages. TIME, 'MM/DD
我收到这些错误: AnonymousPath\Anonymized.vb : error BC30037: Character is not valid. AnonymousPath\Anonymiz
我刚刚安装了 gridengine 并在执行 qstat 时出现错误: error: commlib error: got select error (Connection refused) erro
嗨,我正在学习 PHP,我从 CRUD 系统开始,我在 Windows 上安装了 WAMP 服务器,当我运行它时,我收到以下错误消息。 SCREAM: Error suppression ignore
我刚刚开始一个新项目,我正在学习核心数据教程,可以找到:https://www.youtube.com/watch?v=zZJpsszfTHM 我似乎无法弄清楚为什么会抛出此错误。我有一个名为“Exp
当我使用 Jenkins 运行新构建时,出现以下错误: "FilePathY\XXX.cpp : fatal error C1853: 'FilePathZ\XXX.pch' precompiled
我是一名优秀的程序员,十分优秀!