Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6155451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:26:16+00:00 2026-05-23T20:26:16+00:00

I need to perform a search operation into my SQLite DB. In my Activity,

  • 0

I need to perform a search operation into my SQLite DB.

In my Activity, I have EditText for entering the keyword and a search Button. Once the user clicks the button, the EditText text will be stored in the keyword and sent to a search(String keyword) method in the DBHelper class.

I have this code in my SearchActivityfor onCreate() and onClick():

//SearchActivity class extends ListActivity and implements OnClickListener 
Button search;
DataBaseHelper myDbHelper;
SimpleCursorAdapter ca;
ListView lv;
EditText txt;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.search_layout);

    txt = (EditText) findViewById(R.id.search_term);
    search = (Button) findViewById(R.id.search_button);

    search.setOnClickListener(this);
}

public void onClick(View v) {
    try {
        myDbHelper.openDataBase();
    } catch (SQLException sqle) {}

    try {
    String keyword= txt.getText().toString();
    Cursor cursor = myDbHelper.search(keyword); //A method in my DB
    cursor.moveToFirst();
    String[] columns = {cursor.getColumnName(1)}; 
    int[] columnsLayouts = {R.id.item_title};
    ca = new SimpleCursorAdapter(this.getBaseContext(), R.layout.items_layout, cursor,columns , columnsLayouts);
    lv = getListView();
    lv.setAdapter(ca);

    } catch(Exception e){}
}

However, I got NullPointerException in the LogCat!! I couldn’t find where the error is.

Anyone can help ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:26:17+00:00Added an answer on May 23, 2026 at 8:26 pm

    The description to the NullPointerException could be a little more informative. But it is very likely that the NullPointerException occurs here:

    1: Cursor cursor = myDbHelper.search(keyword); //A method in my DB
    2: cursor.moveToFirst();
    3: String[] columns = {cursor.getColumnName(1)}; 
    

    or here:

    1: try {
    2:    myDbHelper.openDataBase();
    3: } catch (SQLException sqle) {}
    

    Either in the first part in line 1: or 2: or in the second part in line 2:

    You should always check if objects which rely on the existence of data are not null. So you should check if cursor is null. Another thing could be that you never initialize myDbHelper.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to perform search and replace operations on large blocks of
I need to write webapp where user will be able to perform search based
I have a set of data on which I need to perform a topological
I'm new to ASP.NET MVC, but I need to perform a search for articles
I have a table with 117000 or so records. I need to perform a
I need to perform my script (a search) on all the files of a
I need to perform google search to retrieve the number of results for a
I need to perform a regular expression search for a string x in another
I need to perform deletion of the document from lucene search index. Standard approach
I need to be able to perform search on secondary indexes using only <,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.