Search code examples
javamysqllistviewandroid-studiocursor

no such column error (code 1) while compiling my query


I have these column on my announcement table: announceno(autoincrement), announceby(text), announcetitle(text), announcecontent(text).

My activity views the content on listview by selecting the title from spinner. So I have this query where I need to get the title from the spinner and load the query while its equal to the title. "NEW TITLE" is the content of spinner.

I have this error(updated):

android.database.sqlite.SQLiteException: no such column: announcetitle (code 1): , while compiling: SELECT * FROM tablemessage where announcetitle =?

My query(updated):

    public Cursor announcements (String title){
    SQLiteDatabase db = DBHelper.getWritableDatabase();

    String selectQuery = "SELECT * FROM " + TABLE_MESSAGE +" where " +
            KEY_ANNOUNCETITLE + " =  ?";
    Cursor data = db.rawQuery(selectQuery , new String[]{title});


    return data;
}

My Listview(updated):

    public void myMethod() {
    if(spnr1.getSelectedItem().toString() == "--SELECT TITLE--"){


    }else{

        ArrayList<String> theList = new ArrayList<>();

        String a = et16.getText().toString();
        String h = spnr1.getSelectedItem().toString();
        Cursor data = db.announcements(h);


            if (data.moveToFirst()) {
                do {

                    theList.add(data.getString(3));
                    ListAdapter listAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, theList);
                    lv.setAdapter(listAdapter);
                } while (data.moveToNext());
            }}


    }

Solution

  • Thanks. Turns out that my TABLE is supposed to be announcement table not message table. Thats why theres no such column.