Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid sqlite database copy error in real HTC phone
    primarykey
    data
    text
    <p>I have to set up 2 database for one application. I did &amp; working fine in the emulator.Emulator minSDKVersion is : 8 real phone version is :2.2.1. It support. When I setup the database in real phone I couldn't set up. Always I am getting unable create DB.I think one is rooted one, because when I go to File explore -> data. I couldn't open data folder.</p> <p>I have doubt in apk, because My application size is 8 MB.It contain database in asset folder. That size is 4.65 MB. But apk file size is 1.14MB.</p> <p>How it will read from asset folder(In the real phone)?</p> <p>I really don't know whether it is wrong or right..These are my doubt.Please explain me.</p> <p>I got error this :</p> <p><img src="https://i.stack.imgur.com/sIWo6.png" alt="enter image description here"> Please help me. </p> <p>Is there any mistake my coding part or other than anything?</p> <p>Please help me. </p> <p>Thanks in advance....</p> <p><strong>Edited</strong></p> <p>This is my code for copyDatabase:</p> <p>public class DataBaseMasterHelper extends SQLiteOpenHelper {</p> <pre><code>// The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.android.xont.controller/databases/"; private static String DB_NAME = "MasterUserVentura_HEMA.db"; private SQLiteDatabase ventura; private Context myContext; private DataBaseHelper myDbHelper; public DataBaseMasterHelper(Context context) { super(context, DB_NAME, null, 1); this.myContext = context; } /** * Creates a empty database on the system and rewrites it with your own * database. **/ public void createDataBase() throws IOException { boolean dbExist = checkDataBase(); File Path = myContext.getDir("Data", 0); File DBFile = new File(Path, DB_NAME); System.out.println("-------" + DB_NAME); if(!DBFile.exists()) //Need to copy... copyDataBase(myContext, DBFile); } public boolean checkDataBase() { SQLiteDatabase checkDB = null; try { String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { e.printStackTrace(); } if (checkDB != null) { checkDB.close(); } return checkDB != null ? true : false; } private void copyDataBase(Context Ctxt, File DBFile) throws IOException { InputStream myInput = myContext.getAssets().open(DB_NAME); String outFileName = DB_PATH + DB_NAME; OutputStream myOutput = new FileOutputStream(outFileName); byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer)) &gt; 0) { myOutput.write(buffer, 0, length); } myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { String myPath = DB_PATH + DB_NAME; ventura = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Override public synchronized void close() { if (ventura != null) super.close(); ventura.close(); } </code></pre> <p>and calling like this:</p> <pre><code> MyGrid.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position,long id) { if (position == 0) { try { myDbMasterHelper.createDataBase(); Toast.makeText(DatabaseSetupActivity.this, "Successfully copied database",Toast.LENGTH_SHORT).show(); } catch (IOException ioe) { Toast.makeText(DatabaseSetupActivity.this, "Unable to create database",Toast.LENGTH_SHORT).show(); ioe.printStackTrace(); }catch (Exception ioe) { Toast.makeText(DatabaseSetupActivity.this, "Unable to create database",Toast.LENGTH_SHORT).show(); ioe.printStackTrace(); } }else if (position == 1) { try { myDbHelper.createDataBase(); Toast.makeText(DatabaseSetupActivity.this, "Successfully copied database",Toast.LENGTH_SHORT).show(); } catch (IOException ioe) { Toast.makeText(DatabaseSetupActivity.this, "Unable to create database",Toast.LENGTH_SHORT).show(); ioe.printStackTrace(); }catch (Exception ioe) { Toast.makeText(DatabaseSetupActivity.this, "Unable to create database",Toast.LENGTH_SHORT).show(); ioe.printStackTrace(); } } } }); </code></pre> <p>working fine the emulator. If the file size problem, then should have get error in emulator also?</p> <p>I got error like this:</p> <pre><code> java.io.FileNotFoundException: /data/data/com.android.xont.controller/databases /MasterUserVentura_HEMA.db (No such file or directory) </code></pre> <p>I have changed e.printStackTrace() instead of throw expecption.</p> <p>I think,This is not file size problem.because I did same thing in small size 300kb(testng2.db).That one also giving same error</p> <p>My real phone is <strong>HTC HD2 its Windows Mobile® 6.5 Professional.</strong></p> <p>Please help me.</p> <p>Thanks in advance...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload