2

I've got file named plik in assets folder. My sqlhelper has a method called databaseExist():

public boolean databaseExist()
{   
    System.out.println(DB_PATH + DB_NAME);
    File dbFile = new File(DB_PATH + DB_NAME);
    return dbFile.exists();
}

My package name is:

package pl.mobiledietplanner;

Path and name is set as:

private static String DB_PATH = "/data/data/pl.mobiledietplanner/databases/";
private static String DB_NAME = "plik";

In the activity I invoke this method:

MyDBHelper helper = new MyDBHelper(this);       
System.out.println(helper.databaseExist());

The result is:

/data/data/pl.mobiledietplanner/databases/plik
false

I've done everything as described on the blog.
Could anyone tell me what I did wrong?

EDIT:

I also opened File Explorer as said here and added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />. But the data folder is empty.

Community
  • 1
  • 1
Kamil
  • 1,456
  • 4
  • 32
  • 50

2 Answers2

0

the files in asserts folder is not in your DB_PATH, you can do like this:

AssetManager am = null;
·am = getAssets();
·InputStream is = am.open("filename");

then judge whether the inputstream is null

note: my english is not so good,please don't mind

0

Why didn't you follow the checkDatabase() on the blog that you are referring to?

private boolean checkDataBase(){

  SQLiteDatabase checkDB = null;

  try{
    String myPath = DB_PATH + DB_NAME;
    checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

  }catch(SQLiteException e){
    //database does't exist yet.
  }

  if(checkDB != null){
    checkDB.close();
  }

  return checkDB != null ? true : false;
}
Rick Royd Aban
  • 904
  • 6
  • 33
  • I did: `sqlite returned: error code = 14, msg = os_unix.c: open() at line 27701 - "" errno=2 path=/data/data/pl.mobiledietplanner/databases/plik, db=/data/data/pl.mobiledietplanner/databases/plik` `sqlite3_open_v2("/data/data/pl.mobiledietplanner/databases/plik", &handle, 1, NULL) failed` – Kamil Dec 15 '13 at 02:33