简体   繁体   中英

How to fetch record from Sqlite

This is my method in DBMethods class:

public void getResult(EditText keyWord2){

    EditText keyWord = null;

    String SQL ="localSearch.php?query="+keyWord.getText();
    mDb.rawQuery(SQL, null);
}

And this is my method in which I am opening Database and all that in webServices class.

public void startSearch(View v){

    keyWord = (EditText)findViewById(R.id.searchField);
        String data = null;
        DBMethods mDbHelper = new DBMethods(this);         
        mDbHelper.createDatabase();       
        mDbHelper.open(); 

        mDbHelper.getResult(keyWord);
        mDbHelper.close();

}

When I try to fetch data from the database by entering some keyword in the search bar, a force close error occurs.

EditText keyWord = null;

String SQL ="localSearch.php?query="+keyWord.getText();

Keyword is null, this will give null pointer exception.

I think your SQL variable must be

localSearch.php?query="+**keyWord2**.getText();

Make sure that you uninstall the already installed same application in your Emulator. Because once we Run our app that Sqlite DB installed in our Emulator and can't be edited. So uninstall your app and then Run again your app after changing .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM