简体   繁体   English

为什么SQLite Database无法在android studio的文件资源管理器中显示?

[英]Why SQLite Database not showing in File Explorer in android studio?

in order to working with SQLite in android, I wrote this code: 为了在android中使用SQLite,我编写了以下代码:

public class TimeTrackerOpenHelper extends SQLiteOpenHelper {
     private static final int DATABASE_VERSION = 1;

     // Database Name
     private static final String DATABASE_NAME = "timetracker.db";

     public TimeTrackerOpenHelper(Context context) {
           super(context, DATABASE_NAME, null, DATABASE_VERSION);
     }

     @Override
     public void onCreate(SQLiteDatabase db) {
            db.execSQL("create table timerecords " +
                  "(id integer primary key, time text, notes text)");
     }

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

and also for instantiating of above class, I added following code to one of my activity class oncreate method: 为了实例化上述类,我将以下代码添加到我的一个活动类oncreate方法中:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ListView listView = (ListView) findViewById(R.id.times_list);
    adapter = new TimeTrackerAdapter();
    listView.setAdapter(adapter);

    TimeTrackerOpenHelper openHelper = new TimeTrackerOpenHelper(this);
    Log.d("databaseCreation", openHelper.toString());
    openHelper.close();
} 

For monitoring the result of each query that I send to my timetracker.db, I need to access to my database file. 为了监视发送到timetracker.db的每个查询的结果,我需要访问我的数据库文件。 I do the following steps: 1.Run your application. 我执行以下步骤:1.运行您的应用程序。 2.Go to Tools--->Android---->Device Monitor. 2.转到工具--> Android ---->设备监视器。 3.Find your application name in left panel. 3.在左侧面板中找到您的应用程序名称。 4.Then click on File Explorer tab. 4.然后单击“文件资源管理器”选项卡。 5.Select data folder. 5.选择数据文件夹。 6.Select data folder again and find your app or module name. 6.再次选择数据文件夹,然后找到您的应用或模块名称。 7.Click on your database name. 7.单击您的数据库名称。 8.On right-top window you have an option to pull file from device. 8.在右上方的窗口中,您可以选择从设备中提取文件。 9.Click it and save it on your PC. 9.单击并将其保存在您的PC上。 10.Use FireFox Sqlite manager to attach it to your project. 10.使用FireFox Sqlite管理器将其附加到您的项目。

but I have to say that there is not any trace of my .db file. 但是我不得不说我的.db文件没有任何痕迹。 So how can I find that? 那我怎么找到呢?

Your database will not be created until you call getReadableDatabase() or getWriteableDatabase() on the SQLiteOpenHelper . 您的数据库将不会被创建,直到调用getReadableDatabase()getWriteableDatabase()SQLiteOpenHelper Simply creating the instance of the SQLiteOpenHelper will not do that. 简单地创建SQLiteOpenHelper的实例将无法做到这一点。

卸载并重新安装该应用程序,它将起作用,因为您已将TimeTrackerOpenHelper类更改 ..

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM