美好的一天!
在将数据库实现到我的应用程序时遇到问题。 让我感到困惑的是,我导入了一个名为itemsDB的数据库,该数据库对我有用。如果我使用任何其他数据库(让我们谈论 myDB.db ),则会遇到目录不存在的问题。
似乎很多人都遇到了这个问题,但是我检查了Advice File Explorer中是否存在数据库,并且它是:
因此,这排除了其他帖子中提到的大多数问题。
所以我说一切都在 itemDB 上运行,这意味着如果我使用:
private static String DB_Name = "itemsDB.db";
private String DB_table = "Items_neu";
一切正常。
如果我要使用新的数据库“ myDB.db”,则不会在设备中找到新资产。我检查过:
Cursor check;
check = db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null);
if (check.moveToFirst()) {
while ( !check.isAfterLast() ) {
Toast.makeText(mContext, "Table Name=> "+check.getString(0), Toast.LENGTH_LONG).show();
Log.e("table name:", check.getString(0));
check.moveToNext();
}
}
仅产生“ android_metadata”作为唯一表。 对于 myItem.db ,我也找到了正确的表 Item_neu 。
请让我们现在分析我的代码:
public class DBHelper extends SQLiteOpenHelper {
private static String DB_Path ="";
private static String DB_Name = "myDB.db";
// private static String DB_Name = "itemsDB.db";
private String DB_table = "tableItems";
// private String DB_table = "Items_neu";
private SQLiteDatabase mDataBase;
private Context mContext = null;
public DBHelper(Context context) {
super(context, DB_Name, null, 1);
DB_Path = "/data/data/"+ context.getPackageName()+"/databases/";
this.mContext = context;
}
我编辑了一个checkDataBase方法,您可以在文章末尾找到它。
The logchat gives me the following errors: (updated)
2018-10-19 16:32:56.437 1053-1053/com.example.chris.projectartifact E/Does DB exsist?:: Yes it does indeed exsits Christian!!!
2018-10-19 16:32:58.157 1053-1053/com.example.chris.projectartifact E/table name:: android_metadata
2018-10-19 16:32:58.158 1053-1053/com.example.chris.projectartifact E/SQLiteLog: (1)
2018-10-19 16:32:58.161 1053-1053/com.example.chris.projectartifact E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.chris.projectartifact, PID: 1053
android.database.sqlite.SQLiteException: no such table: tableItems (Sqlite code 1): , while compiling: SELECT * FROM tableItems, (OS error - 2:No such file or directory)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:925)
at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:536)
at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:603)
at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:63)
at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1397)
at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1331)
at com.example.chris.projectartifact.DBHelper.getAllItems(DBHelper.java:181)
at com.example.chris.projectartifact.bb_Items.itemActivity$2.onClick(itemActivity.java:126)
at android.view.View.performClick(View.java:6291)
at android.widget.CompoundButton.performClick(CompoundButton.java:135)
at android.view.View$PerformClick.run(View.java:24931)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7425)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
2018-10-19 16:32:58.761 2862-2862/com.example.chris.projectartifact E/MemoryLeakMonitorManager: MemoryLeakMonitor.jar is not exist!
2018-10-19 16:32:58.764 2862-2862/com.example.chris.projectartifact E/Minikin: Could not get cmap table size!
总结一下:
如果有任何机会可以帮助我进行斗争,我对此将感到非常高兴。
编辑:这是我自己取得的一些进步。我编辑了一个新的CheckDataBase,它显示数据库已存在,但是找不到表
private boolean checkDataBase_new() {
File databasePath = mContext.getDatabasePath(DB_Name);
if(databasePath.exists()){
Log.e("Does DB exsist?:","Yes it does indeed exsits Christian!!!");
}else{
Log.e("Does DB exsist?:","No that is causing the issue!");
}
/* Thoughts: So the DB Path for myDB exists, and we can find it. But there is just no readable table! */
return databasePath.exists();
}
致以最诚挚的问候 CG
答案 0 :(得分:0)
好吧,几个小时后,我终于找到了导致我的问题的原因!
在复制Assets文件夹中的数据库时,已重命名为DB,这显然导致了很多问题。
所以,男孩,在资产文件夹中复制数据库时,请勿重命名数据库!