Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This might seem simple, but try taking off the extension from the database name. i.e., make the path <code>"/data/data/com.testapp.test/databases/pbaMainDb"</code> and take the extension off the file when you put it in your assets folder as well.</p> <p>Also, I think there might be a size limitation on the database file size. How big is your file?</p> <p>And one final possibility: right after the app crashes, open it up again (not compile and install but just open it up again on the device) and see if it works. Sometimes the <code>databases</code> folder is not created on the first time around so you might have to go in and create it with some thing like</p> <pre><code>File f = new File(DB_PATH); if (!f.exists()) { f.mkdir(); } </code></pre> <p>EDIT: A couple more question. After looking over the tutorial you used, did you also use the <code>createDataBase()</code> method as he shows at the very end?</p> <p>Also, before you perform your query try calling <code>myDbHelper.close();</code> and then call the open method again. It is possible that the empty version that he creates in the tutorial is still open and needs to be closed on the first time around</p> <p>Let me know how these go and I will try to keep helping you if necessary.</p> <p><strong>EDIT:</strong> Replace your <code>onCreate</code> and <code>fetchAllTables</code> with my edits below. For some reason, you had created two instances of the <code>DbHelper</code> class so I removed that. Also, I can't see where you declared <code>myDbHelper</code> that you used on onCreate, but get rid of all references to that. We will only use one instance of DbHelper to interact with the database, and that is <code>db</code>. As you can see, I create this as a class variable that we will use throughout the entire class and instantiate and open once in <code>onCreate</code>. Also pay attention if the error changes, because I am only focusing right now on getting the opening of the database to work.</p> <pre><code>DbHelper db; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.lists); db = new DbHelper(this); try { db.createDatabase(); } catch (IOException ioe) { throw new Error ("Unable to create database"); } try { db.close(); db.openDataBase(); } catch(SQLException sqle){ throw sqle; } } public Cursor fetchAllTables() { return db.rawQuery("SELECT name FROM sqlite_master WHERE type='table'", null); } </code></pre>
 

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