Usof Dashtban
Usof Dashtban

Reputation: 1

Why There Is No Database File

When I Run My App I Don't See Any Database File In Dir >> Android >> Data >> packagename.... And Also There Is No Crash Or Error:

My dpopenhelper Class:

public class dbopenhelper extends SQLiteOpenHelper {

   public static final String dbname = "dbtest";
   public static final String tblname = "tblname";

   public static final String cid = "id";
   public static final String cquestion = "queston";
   public static final String canswe = "answer";

   public static final String createtbl = "CREATE TABLE "+ tblname +"("+cid+" INTEGER PRIMARY KEY AUTOINCREMENT,"+cquestion+" TEXT,"+canswe+" TEXT);";

   public dbopenhelper(Context context) {
      super(context, dbname, null, 1);
   }

   @Override
   public void onCreate(SQLiteDatabase db) {

      db.execSQL(createtbl);

   }

   @Override
   public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

   }
}

And In My MainActivity

public class MainActivity extends AppCompatActivity {

   private dbopenhelper dbm;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      dbm = new dbopenhelper(this);
      dbm.getWritableDatabase();
   }
}

Upvotes: 0

Views: 83

Answers (1)

dxt
dxt

Reputation: 122

Are you trying to access from an emulator or real device.... real device would need to be rooted so as to access the data directory that has the db file but I guess you could try to use getDatabasePath("your_db_name") in the app to return the file object then use getAbsolutePath() to get accurate path and try navigating to that path and if u see the file, rename it adding the .db3 extension and access it in SQLiteExplorer

Upvotes: 1

Related Questions