I have a sql database and I want a button to perform a search in the database when the user clicks on it. At the moment, I use the onclick method which I want to execute the function request() defined in the following way
public void request(){
SQLiteDatabase db = mDbHelper.getReadableDatabase();
String[] projection = {
FeedReaderContract.FeedEntry._ID,
FeedReaderContract.FeedEntry.COLUMN_NAME_TITLE,
FeedReaderContract.FeedEntry.COLUMN_NAME_UPDATED,
};
String sortOrder =
FeedReaderContract.FeedEntry.COLUMN_NAME_UPDATED + " DESC";
Cursor c = db.query(
FeedReaderContract.FeedEntry.TABLE_NAME, // The table to query
projection, // The columns to return
null, // The columns for the WHERE clause
null, // The values for the WHERE clause
null, // don't group the rows
null, // don't filter by row groups
sortOrder // The sort order
);
}
Here is the scheme of the database
public final class FeedReaderContract {
public FeedReaderContract() {
}
/* Inner class that defines the table contents */
public static abstract class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = " title";
public static final String COLUMN_NAME_UPDATED = " updatedtitle";
}}
However, when I click the application crashes. Where is the problem?
Aucun commentaire:
Enregistrer un commentaire