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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:54:02+00:00 2026-05-25T15:54:02+00:00

I try to convert my Cursor data to a arraylist<String[]>. But at the end

  • 0

I try to convert my Cursor data to a arraylist<String[]>. But at the end all the data in the arraylist is overwrited with the last row. What do i do wrong?

Cursor c = myDbHelper.getLvl1Cata();
String[] data = new String[3];
c.moveToFirst();
while(!c.isAfterLast()) {
    data[0] = Integer.toString(c.getInt(0));
    data[1] = c.getString(1);
    data[2] = Integer.toString(c.getInt(2));
    Log.e("cc", data[1]);
    catalogueData.add(data);
    c.moveToNext();
}   
  • 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-25T15:54:03+00:00Added an answer on May 25, 2026 at 3:54 pm

    Try this

    Cursor c = myDbHelper.getLvl1Cata();
    String[] data;
    if (c != null) {
        while(c.moveToNext()) {
            data = new String[3]; // Note this addition
            data[0] = Integer.toString(c.getInt(0));
            data[1] = c.getString(1);
            data[2] = Integer.toString(c.getInt(2));
            Log.e("cc", data[1]);
            catalogueData.add(data);
        }
        c.close();
    }
    

    data is an array of strings. In the original code, you added the same array to your catalogueData structure several times. You changed the value of the array’s contents each time, but it was still the same array object. So you ended up with catalogueData holding several references to a single array, and that array can only have one value for data[0]: the last thing you set it to.

    This answer fixes that by using a new and different array for each row in the cursor.

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

Sidebar

Related Questions

I want to try to convert a string to a Guid, but I don't
I try to convert string to ListViewItem : ListViewItem str = (ListViewItem)Convert.ChangeType(az, typeof(ListViewItem)); but
We try to convert from string to Byte[] using the following Java code: String
I try to convert clean columnwise data to tables in tex. I am unable
I try to convert a string into a date in t-sql. However get results
I try to convert an anonymous type to class but I don't. My code
I try to convert a sjis string to utf-8 using the iconv API. I
I try to convert a string to NSDATE with no luck unfortunately. Friday, October
I try to convert a ASN.1 Byte Array into a String with Java. My
I try to convert string type dd.MM.yyyy HH:mm:ss.mmm to the datetime using the way

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.