Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite Android - MODE_WORLD_WRITEABLE cannot be resolved to a variable
    primarykey
    data
    text
    <p>My application is a soundboard app, but there is a lot of sounds in categories. Each category is running in a different activity. So, the first activity call the others when the user select the category.</p> <p>The app have more than 200 sounds and I started to make a SQLite DB so the user can select the favorite sounds and show them in a separate activity.</p> <p>It is already working but the code is in the activity, when I put the sqlite code in a method inside another class (if I want to change something it will make my work easier because there is 20 categories) it gave me the 'cannot be resolved to a variable' for <code>MODE_WORLD_WRITEABLE</code>.</p> <p>Here's the method:</p> <pre><code>public void cria(String titulo,int id){ SQLiteDatabase sampleDB = null; try { sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, CODE_WORLD_WRITEABLE, null); sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + SAMPLE_TABLE_NAME + " (titulo VARCHAR, id INT);"); sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values ('" + titulo + "'," + id + ");"); } catch (SQLiteException se ) { Log.e(getClass().getSimpleName(), "Could not create or Open the database"); } finally { //nothin to do } } </code></pre> <p>I have tried to use (String titulo,int id, Context cont) and <code>cont.CODE_WORLD_WRITEABLE</code> but then it gives error like <code>openOrCreateDatabase is undefined for the type banco (banco is the class name)</code>.</p> <p>How can I use the <code>openOrCreateDatabase</code> in another class that is not an activity ? If you guys can show me a snippet.</p> <p>=========EDIT===========</p> <p>As zrgiu solved the problem, here goes my code in the banco class:</p> <p>public class banco{</p> <pre><code>private final static String SAMPLE_DB_NAME = "myFriendsDb"; private final static String SAMPLE_TABLE_NAME = "friends"; public static void cria(String titulo,int id, Context cont){ SQLiteDatabase sampleDB = null; try { sampleDB = cont.openOrCreateDatabase(SAMPLE_DB_NAME, Context.MODE_WORLD_WRITEABLE, null); sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " + SAMPLE_TABLE_NAME + " (titulo VARCHAR, id INT);"); sampleDB.execSQL("INSERT INTO " + SAMPLE_TABLE_NAME + " Values ('" + titulo + "'," + id + ");"); } catch (SQLiteException se ) { Log.e(cont.getClass().getSimpleName(), "Could not create or Open the database"); } finally { sampleDB.close(); } } </code></pre> <p>}</p> <p>And in the activity I use:</p> <p>banco.cria(somestring,someint, this);</p> <p>Again, thank you zrgiu.</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.
    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