我正在开发一个使用sqlite db存储记录的应用程序。我正在SDK 1.5上开发这个应用程序..当我在1.5设备上测试应用程序时,它运行良好但是当我尝试在1.6设备上运行它时,我得到一个强制关闭消息,其中包含以下logcat输出:
03-19 09:31:35.206:ERROR / AndroidRuntime(224):未捕获的处理程序:由于未捕获的异常导致主线程退出
03-19 09:31:35.226:ERROR / AndroidRuntime(224):java.lang.RuntimeException:无法启动活动ComponentInfo {com.abc.android/com.abc.android.app}:android.database。 sqlite.SQLiteException:无法打开数据库文件
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2454)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2470)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread.access $ 2200(ActivityThread.java:119)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1821)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.os.Handler.dispatchMessage(Handler.java:99)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.os.Looper.loop(Looper.java:123)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread.main(ActivityThread.java:4310)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):at java.lang.reflect.Method.invokeNative(Native Method)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):at java.lang.reflect.Method.invoke(Method.java:521) 03-19 09:31:35.226:ERROR / AndroidRuntime(224):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):at dalvik.system.NativeStart.main(Native Method)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):引起:android.database.sqlite.SQLiteException:无法打开数据库文件
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteDatabase.dbopen(原生方法)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteDatabase。(SQLiteDatabase.java:1697)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:738)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:760)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:753)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ApplicationContext.openOrCreateDatabase(ApplicationContext.java:473)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:193)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:98)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):at com.abc.android.DbAdapter.open(DbAdapter.java:101)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在 com.abc.android.class1.onCreate(class1.java:105)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2417)
03-19 09:31:35.226:ERROR / AndroidRuntime(224):... 11更多
DBAdapter.java
public DbAdapter open() throws SQLException {
Log.d("DbAdapter", "in DbAdapter open()");
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase(); // line 101
return this;
}
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_QUERY);
}
class1.java
mDB = new DbAdapter(Class1.this);
mDB.open(); // line 105
请帮帮我..我该怎么做????
答案 0 :(得分:1)
确保DATABASE_NAME
包含的值只是一个文件名,而不是更多,没有斜杠等。
像这样:
final String DATABASE_NAME = "mydata.db";
如果看起来不错,请从手机应用程序菜单中卸载您的应用并重新安装。