具有四列的应用程序

An app with four columns

我尝试了以下代码,但是当我点击查看数据库中存储的内容时应用程序崩溃了。

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;

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)

您传递的是字符串数组而不是字符串。

改变这个:

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

有了这个:

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