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);
}
我在android中为db连接编写代码,但我得到这样的ERROE:
sqlite3_open_v2("/data/data/com.muthu,tamil/databases/aathichudi.db", &handle, 1, NULL) 失败 sqlite3_open_v2("/data/data/com.muthu,tamil/databases/aathichudi.db", &handle , 1, NULL) 失败的 sqlite 返回:错误代码 = 14,msg = 无法在源代码行 25467 打开文件 sqlite3_open_v2("/data/data//data/data/com.muthu.tamil/files/databases/aathichudi.db" , &handle, 1, NULL) 失败关闭 VM threadid=1: 线程退出未捕获异常 (group=0x4001d800) 致命异常: main java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.muthu.tamil/com.muthu .tamil.HomeActivity}:android.database.sqlite.SQLiteException:无法在 android.app.ActivityThread 的 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663) 打开数据库文件。handleLaunchActivity(ActivityThread.java:2679) 在 android.app.ActivityThread.access$2300(ActivityThread.java:125) 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 在 android.os.Handler.dispatchMessage( Handler.java:99) 在 android.os.Looper.loop(Looper.java:123) 在 android.app.ActivityThread.main(ActivityThread.java:4627) 在 java.lang.reflect.Method.invokeNative(Native Method)在 java.lang.reflect.Method.invoke(Method.java:521) 在 com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 在 com.android.internal.os.ZygoteInit.main (ZygoteInit.java:626) at dalvik.system.NativeStart.main(Native Method) 原因:android.database.sqlite.SQLiteException:无法在 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) 在 com.muthu.tamil.HomeActivity.onCreate(HomeActivity.java:41) 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread. java:2627) ... 11 更多Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 更多Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627) ... 11 更多