Reputation: 1252
public class DataBaseHelper extends SQLiteOpenHelper
{
private static String DB_NAME;
private static String DB_PATH = "/data/data/com.muthu.tamil/databases/";
private final Context myContext;
private SQLiteDatabase myDataBase;
static
{
DB_NAME = "aathichudi.db";
}
public DataBaseHelper(Context paramContext)
{
super(paramContext, DB_NAME, null, 1);
DB_PATH = "/data/data/" + paramContext.getPackageName() + "/databases/";
this.myContext = paramContext;
}
private boolean checkDataBase()
{
return new File(DB_PATH + DB_NAME).exists();
}
private void copyDataBase()
throws IOException
{
InputStream localInputStream = this.myContext.getAssets().open(DB_NAME);
FileOutputStream localFileOutputStream = new FileOutputStream(DB_PATH + DB_NAME);
byte[] arrayOfByte = new byte[1024];
while (true)
{
int i = localInputStream.read(arrayOfByte);
if (i <= 0)
{
localFileOutputStream.flush();
localFileOutputStream.close();
localInputStream.close();
return;
}
localFileOutputStream.write(arrayOfByte, 0, i);
}
}
public void createDataBase()
throws IOException
{
if (checkDataBase())
new File(DB_PATH + DB_NAME).delete();
getReadableDatabase();
close();
try
{
copyDataBase();
return;
}
catch (IOException localIOException)
{
}
throw new Error("Error copying database");
}
public Cursor getData(String paramString)
{
return this.myDataBase.rawQuery(paramString, null);
}
public void onCreate(SQLiteDatabase paramSQLiteDatabase)
{
}
public void onUpgrade(SQLiteDatabase paramSQLiteDatabase, int paramInt1, int paramInt2)
{
}
public void openDataBase()
throws SQLException
{
this.myDataBase = SQLiteDatabase.openDatabase(DB_PATH + DB_NAME, null, 1);
}
i write code for db connection in android but i get ERROE like this:
sqlite3_open_v2("/data/data/com.muthu,tamil/databases/aathichudi.db", &handle, 1, NULL) failed sqlite3_open_v2("/data/data/com.muthu,tamil/databases/aathichudi.db", &handle, 1, NULL) failed sqlite returned: error code = 14, msg = cannot open file at source line 25467 sqlite3_open_v2("/data/data//data/data/com.muthu.tamil/files/databases/aathichudi.db", &handle, 1, NULL) failed Shutting down VM threadid=1: thread exiting with uncaught exception (group=0x4001d800) FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{com.muthu.tamil/com.muthu.tamil.HomeActivity}: android.database.sqlite.SQLiteException: unable to open database file at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) at android.app.ActivityThread.access$2300(ActivityThread.java:125) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:123) at android.app.ActivityThread.main(ActivityThread.java:4627) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:521) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) Caused by: android.database.sqlite.SQLiteException: unable to open database file at android.database.sqlite.SQLiteDatabase.dbopen(Native Method) at android.database.sqlite.SQLiteDatabase.(SQLiteDatabase.java:1812) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817) at com.muthu.tamil.sql.DataBaseHelper.openDataBase(DataBaseHelper.java:112) at com.muthu.tamil.HomeActivity.onCreate(HomeActivity.java:41) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 more
Upvotes: 0
Views: 1176
Reputation: 11308
sqlite3_open_v2("/data/data/com.muthu,tamil/databases/aathichudi.db", &handle, 1, NULL)
failed sqlite returned: error code = 14, msg = cannot open file at source line 25467
This error is produced only when your database is not created in the emulator or the device. You can check whether your database is created in your IDE DDMS/file_explorer (/data/data/Ur_pkg_name/databases/ur_db_name).
There was a bug reported related to this problem: http://code.google.com/p/android/issues/detail?id=949
I have come across with several solutions/workarounds people came up with including the followings:
If you are using sharedUserId in your Manifest file changing the sharedUserId of an application and re-installing the application could work since it does not have the required ownership to write to the SQLite database.
Editing the manifest file can eliminate the mistake again. Inside the manifest, make sure that you've entered the correct min sdk version. You could make sure your min SDK version is OK by checking manifest file if there is an exclamation indicator across the left column from the code telling me of your mistake.
I hope one of these solutions work for you too.
Upvotes: 2