0

I developed an android application with sqlite database.Presently my app is in google play.Here i am getting some reported issues like "no such table" while executing select query. Actually i copied my database from Assets folder. Here i followed below given link to copy my database Here is the link what i followed

And by code is like

public class DbFromAssets  extends SQLiteOpenHelper  {  
    private String DB_PATH = Environment.getDataDirectory()+"/data/package/databases/";
    private static String DATABASE_NAME = "mydb.db";
    private final String DEFAULT_DESTINATION = DB_PATH + DATABASE_NAME; 
    @SuppressWarnings("static-access")
    public DbFromAssets(Context ctx)
    {
        super(ctx, DATABASE_NAME, null, 1);
        try
        {
            this.getReadableDatabase();
            InputStream is = ctx.getAssets().open(DATABASE_NAME);
            byte[] buffer = new byte[512];
            int length;
            OutputStream os = new FileOutputStream(DEFAULT_DESTINATION);
            while ((length = is.read(buffer)) >0){
                os.write(buffer, 0, length);
            }
            os.flush();
            os.close();
            is.close();
            this.close();
        }catch (Exception e) {
            e.printStackTrace();
            }       
            }

    @Override
    public void onCreate(SQLiteDatabase db) {
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
}

I am calling this class method in my splash screen as below

  @SuppressWarnings("read-database")                    
            DbFromAssets readdb= new DbFromAssets(SplashActivity.this);

This is working perfectly at my side i tested in emulator and available devices like lg sprint, motorolo droid,etc. i did not get the issues even once but i am getting force close reports in google play account. Can any body have idea why it is giving error. Please advice me it will improve my app.

Thanks in advance.

Raghu Mudem
  • 6,793
  • 13
  • 48
  • 69

0 Answers0