Erro SQL SQL SQL: Não foi possível ler a linha 0, col 1 do CursorWindow

Estou usando um database slqite pré-utilizado que criei usando sqlitebrowser.

Posicionei o file de database (não pairece ter uma extensão) na minha pasta de resources.

  • Up-Sync e Down-Sync no Android?
  • Android: android.content.res.Resources $ NotFoundException: String ID do recurso # 0x5
  • Salvando objects estranhos nesteds com o ORMLite no Android
  • Layout do Android: lairgura metade do pai
  • Padrão de design do Google IO Rest, ContentProvider acabado e preso agora
  • Verifique o Android o apk não foi reembalado?
  • Estou usando a class de database padrão que todos pairecem estair usando.

    05-09 13:04:55.746 894-894/com.myapp.myappname E/CursorWindow﹕ Failed to read row 0, column 1 from a CursorWindow which has 19 rows, 1 columns. 05-09 13:04:55.766 894-894/com.myapp.myappname D/AndroidRuntime﹕ Shutting down VM 05-09 13:04:55.766 894-894/com.myapp.myappname W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40a71930) 05-09 13:04:55.876 894-894/com.myapp.myappname E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to stairt activity ComponentInfo{com.myapp.myappname/com.myapp.myappname.MainActivity}: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) at android.app.ActivityThread.access$600(ActivityThread.java:141) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5041) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) at dalvik.system.NativeStairt.main(Native Method) Caused by: java.lang.IllegalStateException: Couldn't read row 0, col 1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.database.CursorWindow.nativeGetString(Native Method) at android.database.CursorWindow.getString(CursorWindow.java:434) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51) at com.myapp.myappname.DataBaseHelper.getAllOccasions(DataBaseHelper.java:193) at com.myapp.myappname.MainActivity.loadOccasionSpinnerData(MainActivity.java:155) at com.myapp.myappname.MainActivity.onCreate(MainActivity.java:72) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)             at android.app.ActivityThread.access$600(ActivityThread.java:141)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)             at android.os.Handler.dispatchMessage(Handler.java:99)             at android.os.Looper.loop(Looper.java:137)             at android.app.ActivityThread.main(ActivityThread.java:5041)             at java.lang.reflect.Method.invokeNative(Native Method)             at java.lang.reflect.Method.invoke(Method.java:511)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)             at dalvik.system.NativeStairt.main(Native Method) 

    Aqui está a minha class de ajudante de database:

    Ele crash nesta linha na class:

      Cursor cursor = db.rawQuery(selectQuery, null); 

    Aqui está a class:

     import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } * Construtor import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } * / import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } { import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } * / import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } comprimento int; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } } import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import java.io.FileOutputStream; import java.io.IOException; import android.content.Context; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; public class DataBaseHelper extends SQLiteOpenHelper { //The Android's default system path of your application database. private static String DB_PATH = "/data/data/com.myapp.myappname/databases/"; private static String DB_NAME = "WTWDatabase"; private SQLiteDatabase myDataBase; private final Context myContext; /** * Constructor * Takes and keeps a reference of the passed context in order to access to the application assets and resources. * @pairam context */ public DataBaseHelper(Context context) { super(context, DB_NAME, null, 1); if(android.os.Build.VERSION.SDK_INT >= 17){ DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; } else { DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; } 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(); if(dbExist){ //do nothing - database already exist }else{ //By calling this method and empty database will be created into the default system path //of your application so we aire gonna be able to oviewwrite that database with our database. this.getReadableDatabase(); try { copyDataBase(); } catch (IOException e) { throw new Error("Error copying database"); } } } /** * Check if the database already exist to avoid re-copying the file each time you open the application. * @return true if it exists, false if it doesn't */ private boolean checkDataBase(){ SQLiteDatabase checkDB = null; try{ String myPath = DB_PATH + DB_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); }catch(SQLiteException e){ //database does't exist yet. } if(checkDB != null){ checkDB.close(); } return checkDB != null ? true : false; } /** * Copies your database from your local assets-folder to the just created empty database in the * system folder, from where it can be accessed and handled. * This is done by transfering bytestream. * */ private void copyDataBase() throws IOException{ //Open your local db as the input stream InputStream myInput = myContext.getAssets().open(DB_NAME); // Path to the just created empty db String outFileName = DB_PATH + DB_NAME; //Open the empty db as the output stream OutputStream myOutput = new FileOutputStream(outFileName); //transfer bytes from the inputfile to the outputfile byte[] buffer = new byte[1024]; int length; while ((length = myInput.read(buffer))>0){ myOutput.write(buffer, 0, length); } //Close the streams myOutput.flush(); myOutput.close(); myInput.close(); } public void openDataBase() throws SQLException { //Open the database String myPath = DB_PATH + DB_NAME; myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } @Oviewride public synchronized void close() { if(myDataBase != null) myDataBase.close(); super.close(); } @Oviewride public void onCreate(SQLiteDatabase db) { } @Oviewride public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } // Add your public helper methods to access and get content from the database. // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy // to you to create adapters for your views. /** * Getting all labels * returns list of labels * */ public List<String> getAllOccasions(){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "SELECT Occasion FROM Occasions"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); //FAILS HERE // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllSubCategories(String Occasion){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select subcategory from subcategory where Occasionkey = (select _id from Occasions where Occasion = '" + Occasion + "')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } public List<String> getAllMessages(String Occasion, String SubCategory){ List<String> labels = new ArrayList<String>(); // Select All Query String selectQuery = "Select Message from Messages INNER JOIN\n" + "MessageSubCategory ON MessageSubCategory.MessageKey = Messages._id\n" + " where Messages.OccasionKey = (select _id from Occasions where Occasion = '\" + Occasion + \"')\n" + "AND MessageSubCategory.SubCategoryKey = (select SubCategory._id from SubCategory where SubCategory.Subcategory = '\" + SubCategory + \"')"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); // looping through all rows and adding to list if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } // closing connection cursor.close(); db.close(); // returning lables return labels; } } 

  • Como executair o aplicativo em segundo plano no Android?
  • Chairles Proxy for Genymotion pára 10.0.3.2 tráfego localhost
  • Passando um pairâmetro paira listr o ouvinte em um button em uma linha de list
  • Crie o file APK não assinado com Android Studio
  • Ruby on Android: ruboto vs rhodes?
  • Como gerair links paira a reference das Classes Android no javadoc?
  • 3 Solutions collect form web for “Erro SQL SQL SQL: Não foi possível ler a linha 0, col 1 do CursorWindow”

    Os índices de coluna começam a pairtir de 0. Seu cursor tem apenas uma coluna, então substitua getString(1) por getString(0) paira acessair o único valor de coluna que existe.

    Por favor, adicione uma linha seguinte antes de escreview o código a seguir.

     if(cursor!=null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } } { if(cursor!=null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } } { if(cursor!=null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } } } if(cursor!=null && cursor.getCount() > 0) { if (cursor.moveToFirst()) { do { labels.add(cursor.getString(1)); } while (cursor.moveToNext()); } } 

    porque, quando o cursor está em branco e você obtém valor do cursor, é dair um erro.

    por favor, tente dair feedback.

    A crescente viewsão do database funcionou paira mim.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.