Note that there are some explanatory texts on larger screens.

plurals
  1. POSimpleCursorAdapter crashing
    primarykey
    data
    text
    <p>Android keep crashing as it hits the line "SimpleCursorAdapter NotesAdapter = new SimpleCursorAdapter(this, R.layout.manage_notes_noteitem_layout,)</p> <p>I've tried changing all sorts of things, even creating a separate class for the Adapter, but the Adapter class also proves problematic. Either it's the "this"/context or something to do with the custom layout. I'm unsure and I have been looking around for answers.</p> <p>Thanks in advance.</p> <pre><code> String[] columns = new String[] { NotesAdapter.KEY_NoteTitle, NotesAdapter.KEY_Created, NotesAdapter.KEY_NoteText, }; // the XML defined views which the data will be bound to int[] to = new int[] { R.id.note_title, R.id.note_datedcreated, R.id.note_details, }; // create the adapter using the cursor pointing to the desired data //as well as the layout information SimpleCursorAdapter NotesAdapter = new SimpleCursorAdapter( this, R.layout.manage_notes_noteitem_layout, C, columns, to, 0); </code></pre> <p>Update for the NotesAdapter class:</p> <pre><code>public class NotesAdapter extends DBAdapter { public static final String KEY_NoteID = "NoteID"; public static final String KEY_NoteTitle = "NoteTitle"; public static final String KEY_NoteText = "NoteText"; public static final String KEY_Created = "Created"; private static final String DATABASE_TABLE = "notes"; public NotesAdapter(Context ctx) { super(ctx); } public long create(String NoteID, String NoteTitle, String NoteText, String Created) { ContentValues args = new ContentValues(); args.put(KEY_NoteID,NoteID); args.put(KEY_NoteTitle,NoteTitle); args.put(KEY_NoteText,NoteText); args.put(KEY_Created,Created); return mDb.insert(DATABASE_TABLE, null,args); } public boolean delete(String RowID) { return mDb.delete(DATABASE_TABLE, KEY_NoteID + "=" + RowID, null) &gt; 0; } public Cursor fetchAll() { return mDb.query(DATABASE_TABLE, new String[] {KEY_NoteID, KEY_NoteTitle, KEY_NoteText, KEY_Created}, null, null, null, null, null); } public Cursor fetch(long rowId) throws SQLException { Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] {KEY_NoteID, KEY_NoteTitle, KEY_NoteText, KEY_Created}, KEY_NoteID + "=" + rowId, null, null, null, null, null); if (mCursor != null) { mCursor.moveToFirst(); } return mCursor; } </code></pre> <p>}</p> <p>Edit: The cursor does return valid values because I tested it using Toasts.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload