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

  • SEARCH
  • Home
  • 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 8684809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:23:59+00:00 2026-06-12T22:23:59+00:00

I am developing a simple app that inserts in database and searches in the

  • 0

I am developing a simple app that inserts in database and searches in the inserted data

i created the database and i could see all the rows inserted…i want to search for the rows using the Name column

i am having an error and i don’t know where is the error line

below is my code to create the database.

sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);

sampleDB.execSQL("CREATE TABLE IF NOT EXISTS "+SAMPLE_TABLE_NAME +
                    " (Id INT(50), Name VARCHAR," +
                    " Price INT(50), Qty INT(50), Discount INT(50), Category INT(10));");

and here’s the code to search in the database

Button saveButton = (Button) findViewById(R.id.search_button);

        saveButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View arg0) {

                String searchStr = search.getText().toString();

                Cursor c = sampleDB.rawQuery("SELECT Name, Price FROM "+SAMPLE_TABLE_NAME+" WHERE Name like '"+searchStr+"'", null);

                if (c != null ) { 
                    if  (c.moveToFirst()) {
                        do {
                            String name = c.getString(c.getColumnIndex("Name"));
                            int cat = c.getInt(c.getColumnIndex("Category"));
                            results.add("" + name + ",Age: " + cat);
                            Log.v("Fname", name);
                            Log.v("Cat", cat+"");
                        }while (c.moveToNext());
                    }
                }

            }
        });

knowing that searchStr has the name i want to search for in the database

here’s the error i am having

Bad request for field slot 0,-1. numRows = 18, numColumns = 2
FATAL EXCEPTION: main
java.lang.IllegalStateException: get field slot from row 0 col -1 failed

any help please ?

  • 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-06-12T22:24:01+00:00Added an answer on June 12, 2026 at 10:24 pm

    You are selecting only name and price in the query:

    Cursor c = sampleDB.rawQuery("SELECT Name, Price FROM "+SAMPLE_TABLE_NAME+" WHERE Name like '"+searchStr+"'", null);
    

    and then you are trying to access category..

    int cat = c.getInt(c.getColumnIndex("Category"));
    

    So you should add category to your select statement:

    Cursor c = sampleDB.rawQuery("SELECT Name, Price, Category FROM "+SAMPLE_TABLE_NAME+" WHERE Name like '"+searchStr+"'", null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm developing a desktop Mac OS X App that saves its very simple data
I'm developing a simple app that'll use a simple database. So far I thought
I have lately been developing a very simple app for iOS with PhoneGap. All
I'm developing a simple servlet/JSP, data-driven web site on Google App Engine. I've started
I am developing a simple web app that uses the Google translation API in
I'm developing a webapp+android app that has its own registration flow - simple authentication
We are developing an iphone app that needs to process audio data in real
I'm developing a simple app that will allow users to upload their content. I
I'm developing a simple Facebook app that will live in a Page's tab. I'm
I'm developing a simple text editor for iPad. Instead of Core Data, the app

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.