-1

I tried the following code, but the app crashes when I click to view what's stored in the database.

DATABASE_TABLE = "EntriesTable"

String[] columns = new String[] { KEY_ROWID, KEY_STUDENT, KEY_AGE,
            KEY_NUMBER, KEY_CLASS };

    Cursor c = ourDatabase.rawQuery("select " + columns + " from " + DATABASE_TABLE , null);


    String result = "";

            int IROW = c.getColumnIndex(KEY_ROWID);
        int ISTUDENT = c.getColumnIndex(KEY_STUDENT);
    int IAGE = c.getColumnIndex(KEY_AGE);
    int INUMBER = c.getColumnIndex(KEY_ID_NUMBER);
    int ICLASS = c.getColumnIndex(KEY_CLASS);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {


result = result + c.getString(IROW) + "   " + c.getString(ISTUDENT) + "  " + " " + c.getString(IAGE) + "  " + " " + c.getString(INUMBER) + "  " + "  " + c.getString(ICLASS)
                    + "\n";
    }

    return result;

the LogCat:

E/AndroidRuntime(336):
Caused by:
android.database.sqlite.SQLiteException: unrecognized token: "[Ljava.lang.String;@4053eb90 from EntriesTable": , while compiling: select [Ljava.lang.String;@4053eb90 from EntriesTable
01-04 09:59:06.396: E/AndroidRuntime(336):
at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
M.Dixon
  • 23
  • 5

1 Answers1

2

You are passing a string array in place of a string.

Change this:

Cursor c = ourDatabase.rawQuery("select " + columns + " from " + DATABASE_TABLE , null);

with this:

Cursor c = ourDatabase.rawQuery("select " + StringUtils.join(columns, ",") + " from " + DATABASE_TABLE , null);
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115