0

enter image description here By using assets folder, we are reading data i.e,address details based on search keyword: Here is my code

 private SQLiteDatabase db;
    private Cursor c;
 @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    et_search = (EditText) findViewById(R.id.et_search);
    img = (ImageView) findViewById(R.id.img_search);
    list = (ListView) findViewById(R.id.list_search);

    db = openOrCreateDatabase("sample", Context.MODE_PRIVATE, null);


    img.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            search_keyword = et_search.getText().toString();
            arr_data = new ArrayList<ListItems>();
            if (isValid()) {
               SELECT_SQL = "SELECT  ROWID AS _id,* FROM Addresses where Type LIKE '%" + search_keyword + "%'";

                Log.d("daatt",SELECT_SQL);
                try {
                    c = db.rawQuery(SELECT_SQL, null);
                    c.moveToFirst();
                    showRecords();

                } catch (SQLiteException e) {
                    Toast.makeText(getApplicationContext(), "No Data", Toast.LENGTH_LONG).show();
                }

            }

        }
    });


}

private void showRecords() {

        String ugName = c.getString(c.getColumnIndex("Name"));
        String ugaddress = c.getString(c.getColumnIndex("Address"));
        String ugtype = c.getString(c.getColumnIndex("Type"));

        ListItems items = new ListItems();

        // Finish reading one raw, now we have to pass them to the POJO
        items.setName(ugName);
        items.setAddress(ugaddress);
        items.setType(ugtype);

        // Lets pass that POJO to our ArrayList which contains undergraduates as type
        arr_data.add(items);
    }
    ListDataAdapter adapter = new ListDataAdapter(arr_data);
    list.setAdapter(adapter);

    if (c != null && !c.isClosed()) {
        int count = c.getCount();
        c.close();
    }

    Log.d("ListData", "" + arr_data);

}


private boolean isValid() {
    if (search_keyword.length() == 0) {
        Toast.makeText(getApplicationContext(), "please enter valid key word", Toast.LENGTH_LONG).show();
        return false;
    }
    return true;
}

For 1st build we got successful data loaded using list adapter But after clean project, & Rebuild project showing a no such table expection

Please guide us wr we r going wrong Advance Thanks

1
  • 1
    Sounds to me like Clean & Build removes the database. You're re-creating the database, but it contains no tables. So when you're executing statements, it'll throw the no such table exception. Be sure to check beforehand whether the database exists, and if yes whether the necessary tables in it exist. If not, create them. Commented Dec 22, 2016 at 12:39

1 Answer 1

1

As far as I can see from your print, the table you're referring to is called ListOfAddress, ain't it? your SQL is:

SELECT_SQL = "SELECT ROWID AS _id,* FROM Addresses where Type LIKE '%" + search_keyword + "%'";

I might be wrong, but I would double check the query.

Sign up to request clarification or add additional context in comments.

1 Comment

but same after rechanging code SELECT_SQL = "SELECT ROWID AS _id,* FROM ListOfAddress where Type LIKE '%" + search_keyword + "%'";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.