با سلام من یه برنامه دارم که میاد دیتابیس رو از assets می گیره و اونو کپی میکنه،همه ی مراحل انجام میشه،برنامه خطا نمیده،دیتابیس هم در آدرس مورد نظر کپی میشه،به طور کامل هم کپی میشه حجم دیتابیس رو مشاهده کردم،اما وقتی یه دستور Cursor برای گرفتن مقادیر از دیتابیس مینویسم و کارهاشو انجام میدم توی قسمت run این ارور ها رو میده
این فایل main جاوا
اینم database کلاس
E/SQLiteDatabase: Failed to open database 'data/data/ir.dream.a28raz/databases/database'. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (Sqlite code 14): Could not open database, (OS error - 2:No such file or directory) at android.database.sqlite.SQLiteConnection.nativeOpen(Native Method) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:217) at android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:201) at android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:493) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:194) at android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:183) at android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:827) at android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:814) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:714) at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:689) at ir.dream.ssssssssss.database.open(database.java:68) at ir.dream.ssssssssss.MainActivity.onCreate(MainActivity.java:16) at android.app.Activity.performCreate(Activity.java:6367) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2397) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2504) at android.app.ActivityThread.access$900(ActivityThread.java:165) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:150) at android.app.ActivityThread.main(ActivityThread.java:5546) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) I/Process: Sending signal. PID: 28755 SIG: 9 Application terminated.
این فایل main جاوا
package ir.dream.a28raz; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; public class MainActivity extends AppCompatActivity { private database db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); db = new database(this); db.usedb(); db.opendb(); String s = db.dasplay_title(); Toast.makeText(this, s, Toast.LENGTH_SHORT).show(); db.close(); } }
اینم database کلاس
package ir.dream.a28raz; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; public class database extends SQLiteOpenHelper { private Context context; private static String db_name = "database"; private String db_path = "data/data/ir.dream.a28raz/databases/" + db_name; private SQLiteDatabase mydb = null; public database(Context context) { super(context, db_name, null, 1); this.context = context; } @Override public void onCreate(SQLiteDatabase sqLiteDatabase) { } @Override public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) { } public void usedb() { if (checkdb()) { //do nothing; } else { this.getReadableDatabase(); try { copyDB(); } catch (IOException e) { } } } public void opendb() { mydb = SQLiteDatabase.openDatabase(db_path, null, SQLiteDatabase.OPEN_READWRITE); } public boolean checkdb(){ try{ opendb(); } catch(SQLException e) { if (mydb.isOpen()){ mydb.close(); } } //mydb.close(); return mydb !=null ? true:false ; } private void copyDB() throws IOException { InputStream dbInput = context.getAssets().open(db_name); String outFile = db_path ; OutputStream dbOutput = new FileOutputStream(outFile); byte[] buffer = new byte[1024]; int length; while ((length = dbInput.read(buffer))>0) { dbOutput.write(buffer,0,length); } dbOutput.flush(); dbOutput.close(); dbInput.close(); } public void close(){ mydb.close(); } public String dasplay_title(){ Cursor cursor = mydb.rawQuery("select * from table" , null); cursor.moveToFirst(); String s = cursor.getString(1); return s; } }