在我的应用程序中,我试图从数据库中获取一些数据,并将其显示在列表中.当我在Motorola(2.1)和Samsung Ace(2.3)以及一些仿真器中运行该应用程序时,它们运行良好.

但是当我在三星Galaxy Tab-P7500(3.1)中运行时,它显示以下错误

sqlite3_open_v2("/data/data/com.pack.store/databases/chaek.db", &handle, 6, NULL) failed

E/SQLiteDatabase(10021): Failed to open the database. closing it.

E/SQLiteDatabase(10021): android.database.sqlite.SQLiteDatabaseLockedException: database is locked

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1021)

E/SQLiteDatabase(10021): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:750)

E/SQLiteDatabase(10021): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:223)

E/SQLiteDatabase(10021): at com.pack.sp.SPTocPage.getTOC(SPTocPage.java:246)

E/SQLiteDatabase(10021): at com.pack.sp.SPTocPage.onCreate(SPTocPage.java:82)

E/SQLiteDatabase(10021): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)

E/SQLiteDatabase(10021): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)

E/SQLiteDatabase(10021): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)

E/SQLiteDatabase(10021): at android.app.ActivityThread.access$1500(ActivityThread.java:122)

E/SQLiteDatabase(10021): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)

E/SQLiteDatabase(10021): at android.os.Handler.dispatchMessage(Handler.java:99)

E/SQLiteDatabase(10021): at android.os.Looper.loop(Looper.java:132)

E/SQLiteDatabase(10021): at android.app.ActivityThread.main(ActivityThread.java:4028)

E/SQLiteDatabase(10021): at java.lang.reflect.Method.invokeNative(Native Method)

E/SQLiteDatabase(10021): at java.lang.reflect.Method.invoke(Method.java:491)

E/SQLiteDatabase(10021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)

E/SQLiteDatabase(10021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

E/SQLiteDatabase(10021): at dalvik.system.NativeStart.main(Native Method)

E/SQLiteOpenHelper(10021): Couldn't open chaek.db for writing (will try read-only):

E/SQLiteOpenHelper(10021): android.database.sqlite.SQLiteDatabaseLockedException: database is locked

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:1021)

E/SQLiteOpenHelper(10021): at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:750)

E/SQLiteOpenHelper(10021): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:221)

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:149)

E/SQLiteOpenHelper(10021): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:223)

E/SQLiteOpenHelper(10021): at com.pack.sp.SPTocPage.getTOC(SPTocPage.java:246)

E/SQLiteOpenHelper(10021): at com.pack.sp.SPTocPage.onCreate(SPTocPage.java:82)

E/SQLiteOpenHelper(10021): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)

E/SQLiteOpenHelper(10021): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)

E/SQLiteOpenHelper(10021): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)

E/SQLiteOpenHelper(10021): at android.app.ActivityThread.access$1500(ActivityThread.java:122)

E/SQLiteOpenHelper(10021): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)

E/SQLiteOpenHelper(10021): at android.os.Handler.dispatchMessage(Handler.java:99)

E/SQLiteOpenHelper(10021): at android.os.Looper.loop(Looper.java:132)

E/SQLiteOpenHelper(10021): at android.app.ActivityThread.main(ActivityThread.java:4028)

E/SQLiteOpenHelper(10021): at java.lang.reflect.Method.invokeNative(Native Method)

E/SQLiteOpenHelper(10021): at java.lang.reflect.Method.invoke(Method.java:491)

E/SQLiteOpenHelper(10021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)

E/SQLiteOpenHelper(10021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

E/SQLiteOpenHelper(10021): at dalvik.system.NativeStart.main(Native Method)

E/SqliteDatabaseCpp(10021): sqlite3_open_v2("/data/data/com.pack.sp/databases/chaek.db", &handle, 1, NULL) failed

E/SQLiteDatabase(10021): Failed to open the database. closing it.

E/SQLiteDatabase(10021): android.database.sqlite.SQLiteDatabaseLockedException: database is locked

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:983)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:956)

E/SQLiteDatabase(10021): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:233)

E/SQLiteDatabase(10021): at com.pack.sp.SPTocPage.getTOC(SPTocPage.java:246)

E/SQLiteDatabase(10021): at com.pack.sp.SPTocPage.onCreate(SPTocPage.java:82)

E/SQLiteDatabase(10021): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)

E/SQLiteDatabase(10021): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1715)

E/SQLiteDatabase(10021): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1767)

E/SQLiteDatabase(10021): at android.app.ActivityThread.access$1500(ActivityThread.java:122)

E/SQLiteDatabase(10021): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1005)

E/SQLiteDatabase(10021): at android.os.Handler.dispatchMessage(Handler.java:99)

E/SQLiteDatabase(10021): at android.os.Looper.loop(Looper.java:132)

E/SQLiteDatabase(10021): at android.app.ActivityThread.main(ActivityThread.java:4028)

E/SQLiteDatabase(10021): at java.lang.reflect.Method.invokeNative(Native Method)

E/SQLiteDatabase(10021): at java.lang.reflect.Method.invoke(Method.java:491)

E/SQLiteDatabase(10021): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)

E/SQLiteDatabase(10021): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)

E/SQLiteDatabase(10021): at dalvik.system.NativeStart.main(Native Method)

E/android.os.Debug( 284): Dumpstate > /data/log/dumpstate_app_error

以下是我的Db类文件

public class ChaekHelper extends SQLiteOpenHelper

{

private static final int DATABASE_VERSION = 7;

private static final String DATABASE_NAME = "chaek.db";

private List> ALL_TABLES = new ArrayList>();

public ChaekHelper(Context context)

{

super(context, DATABASE_NAME, null, DATABASE_VERSION);

this.onSetCreateQuery(context);

}

@Override

public void onCreate(SQLiteDatabase db)

{

for (int i = 0; i < ALL_TABLES.size(); i++)

{

db.execSQL("CREATE TABLE IF NOT EXISTS " + ALL_TABLES.get(i).get("TABLE_NAME") + " ( "+ ALL_TABLES.get(i).get("FIELD_NAME") + " );");

}

// create Index table

db.execSQL("DROP TABLE IF EXISTS dual;");

db.execSQL("CREATE TABLE dual (idx INTEGER PRIMARY KEY, rownum TEXT);");

db.execSQL("CREATE UNIQUE INDEX idx_rownum ON dual (rownum);");

// create all tables

db.beginTransaction();

try

{

for (int i = 1; i < 100; i++) {

String idxStr = "0" + i;

if (i > 9)

idxStr = idxStr.substring(1);

db.execSQL("INSERT INTO dual (idx, rownum) VALUES (" + i + ",'" + idxStr + "');");

}

db.setTransactionSuccessful();

}

catch (Exception e) {

e.printStackTrace();

}

finally {

db.endTransaction();

}

}

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

for (int i = 0; i < ALL_TABLES.size(); i++) {

db.execSQL("DROP TABLE IF EXISTS " + ALL_TABLES.get(i).get("TABLE_NAME") + ";");

}

onCreate(db);

}

private void onSetCreateQuery(Context context) {

Map params;

// 1. BOOK

params = new HashMap();

params.put("TABLE_NAME", context.getResources().getString(R.string.BOOK_TBL_NAME));

params.put("FIELD_NAME", context.getResources().getString(R.string.BOOK_TBL_FIELDS));

ALL_TABLES.add(params);

// 2. TOC

params = new HashMap();

params.put("TABLE_NAME", context.getResources().getString(R.string.TOC_TBL_NAME));

params.put("FIELD_NAME", context.getResources().getString(R.string.TOC_TBL_FIELDS));

ALL_TABLES.add(params);

// 3. BOOKMARK

params = new HashMap();

params.put("TABLE_NAME", context.getResources().getString(R.string.BM_TBL_NAME));

params.put("FIELD_NAME", context.getResources().getString(R.string.BM_TBL_FIELDS));

ALL_TABLES.add(params);

}

}

为什么会这样发生?有人可以向我解释一下吗….我在此浪费了三天….

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐