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 8929321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:38:56+00:00 2026-06-15T08:38:56+00:00

I want to retrieve the name from database. But I always get error with:

  • 0

I want to retrieve the name from database. But I always get error with:

String name=helper.getProductNameT(cur);

public View getView(int position, View convertView, ViewGroup parent) {
                View tmpView = super.getView(position, convertView, parent);
                Log.i(CN, "getView:" + position);

                final CheckBox cBox = (CheckBox) tmpView.findViewById(R.id.checkD);

                Item tag = (Item) cBox.getTag();

                cBox.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        Cursor cur = null;
                        String name2;
                        Item tag = (Item) v.getTag();
                        if (tag == null)
                            Log.i(CN, "checkbox clicked no tag");

                        else

                                //Cursor c=helper.getProductDirect(String.valueOf(tag.id));

                                Log.i(CN, "checkbox clicked tag=" + tag.id);
                                helper.open();

                                cur=helper.getProductDirect(String.valueOf(tag.id));
                                String name=helper.getProductNameT(cur);

                                try{



                                }catch(Exception e){
                                    Log.e("error", e.toString());
                                }
                                //helper.insertProduct3(list,2, "name");



                        if (cBox.isChecked()) {
                            Log.i(CN, " Checked!");
                            // do some operations here




                            helper.insertProduct3(list,2, "go");
                        } else {
                            Log.i(CN, "NOT Checked!");
                            // do some operations here
                            //helper.updateStatusUnCheck(tag.id);



                        }
                        // notifyDataSetChanged();

                        Intent start = new Intent(AddProductDirect.this,
                                productClass.class);
                    //  start.putExtra(ID_EXTRA, String.valueOf(list));
                        //startActivity(start);
                    }

                });

                return tmpView;
            }

Database.java

public Cursor getProductDirect(String id) {
                String[] arg={id};

                // TODO Auto-generated method stub

                    return (database.rawQuery("SELECT " + SQLiteHelper.product_id
                            + " as _id," + SQLiteHelper.productBar + ","
                            + SQLiteHelper.productName + " ," + SQLiteHelper.productDesp
                            + "," + SQLiteHelper.productQtty + ","
                            + SQLiteHelper.productPrice + ","
                            + SQLiteHelper.productTotalPrice + ","
                            + SQLiteHelper.product_FId + "," + SQLiteHelper.product_Image
                            + "," + SQLiteHelper.product_ShoppingF + ","
                            + SQLiteHelper.product_Status + " FROM "
                            + SQLiteHelper.productTable + " WHERE "+SQLiteHelper.product_id+"=?",arg));



            }
    public String getProductNameT(Cursor c) {
            // TODO Auto-generated method stub
            return ((c.getString(2)));
        }

It keeps returning the error

android.database.CursorIndexOutOfBoundsException: Index -1 requested,
with a size of 1 in String name=helper.getProductNameT(cur);

Anyone know where the mistake is in my coding?

  • 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-15T08:38:57+00:00Added an answer on June 15, 2026 at 8:38 am

    you forgot to call moveToFirst() on cursor that was return from database.rawQuery

    cur=helper.getProductDirect(....);
    if(cur.moveToFirst()){
       /*
       String name=helper.getProductNameT(cur);    
       ... rest code goes here ...
       */
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to retrieve just Rolepermissions where the user name is Bob but not
I have spinner which I populate from SQLite database. But I want to populate
hi i want to retrieve values from SQL database for xml tags using java
I want to retrieve information from my database.I got the input dynamically from user
In my web application, I want to retrieve data from database based on the
In My database I want to retrieve a row from my database . For
Here is the source Table . I want to retrieve the Name , Host
I have a HTML table as follows. I want retrieve row values from this
I want to retrieve the email address from the table and using that to
I am trying to retrieve values from the database using mysql and PHP. The

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.