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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:52:09+00:00 2026-06-06T20:52:09+00:00

So I have a function that gets some coordinates from a sql database and

  • 0

So I have a function that gets some coordinates from a sql database and stores them in an arraylist. I am printing the values as I read them from the cursor and they are good. However when I immediately after loop through and print out the values I stored in the array list, all the values seem to be set to the last value I added to the arraylist. I am doing something wrong here?

code:

public ArrayList<Coord> getCoordMarkers(int myUserId)
{
    Log.d("getCoordMarkers()", "Called");
Coord myCoord = new Coord();
ArrayList<Coord> markerArray = new ArrayList<Coord>();
String sql = "SELECT "+ userId + " , " + timestamp + " , " + coordX + " , " +
                 coordY + " , " + coordType + " , " + coordId + " , " + coordTypeTable+ "." +
                 coordTypeDesc + " FROM " + coordTable + " JOIN " + coordTypeTable + " ON " +
                 coordTable + "." + coordType + " = " + coordTypeTable + "." + coordTypeAbbr +
                 " WHERE " + userId + " = '" + myUserId + "' AND " + coordTypeTable + "." +
                 coordTypeDesc + " != 'User Location';";
    // AND it is a marker
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cur = db.rawQuery(sql, null);
    if( cur.moveToFirst()) {
        do {
            myCoord.userId = cur.getInt(0);
            myCoord.timestamp = cur.getLong(1);
            myCoord.x = cur.getDouble(2);
            myCoord.y = cur.getDouble(3);
            myCoord.coordType = cur.getInt(4);
            myCoord.id = cur.getInt(5);
            myCoord.coordTypeDesc = cur.getString(6);
            markerArray.add(myCoord);
            Log.d("getCoordMarkers()", "X: " + myCoord.x + " Y: " + myCoord.y);
        } while( cur.moveToNext());
    }
    cur.close();
    db.close();
    for( int i = 0; i < markerArray.size(); i++ )
    {
        Coord myCoord2 = markerArray.get(i);
        Log.d("Test Marker", "I: "+ i + " X: " + myCoord2.x + " Y: "+ myCoord2.y);

    }
    return markerArray;
}

The following is the log printout from the above code

06-27 01:46:06.588: DEBUG/getCoordMarkers()(541): Called
06-27 01:46:06.638: DEBUG/getCoordMarkers()(541): X: -122.093451 Y: 37.420599
06-27 01:46:06.638: DEBUG/getCoordMarkers()(541): X: -122.093451 Y: 37.420599
06-27 01:46:06.648: DEBUG/getCoordMarkers()(541): X: -122.094695 Y: 37.419679
06-27 01:46:06.648: DEBUG/getCoordMarkers()(541): X: -122.094695 Y: 37.419679
06-27 01:46:06.648: DEBUG/getCoordMarkers()(541): X: -122.090104 Y: 37.423633
06-27 01:46:06.658: DEBUG/getCoordMarkers()(541): X: -122.090104 Y: 37.423633
06-27 01:46:06.658: DEBUG/getCoordMarkers()(541): X: -122.092078 Y: 37.420464
06-27 01:46:06.658: DEBUG/getCoordMarkers()(541): X: -122.092078 Y: 37.420464
06-27 01:46:06.658: DEBUG/getCoordMarkers()(541): X: -122.091992 Y: 37.420668
06-27 01:46:06.668: DEBUG/getCoordMarkers()(541): X: -122.091992 Y: 37.420668
06-27 01:46:06.668: DEBUG/getCoordMarkers()(541): X: -122.09594 Y: 37.42077
06-27 01:46:06.678: DEBUG/getCoordMarkers()(541): X: -122.09594 Y: 37.42077
06-27 01:46:06.678: DEBUG/getCoordMarkers()(541): X: -122.09255 Y: 37.42118
06-27 01:46:06.678: DEBUG/getCoordMarkers()(541): X: -122.09255 Y: 37.42118
06-27 01:46:06.688: DEBUG/getCoordMarkers()(541): X: -122.095897 Y: 37.423633
06-27 01:46:06.698: DEBUG/getCoordMarkers()(541): X: -122.095897 Y: 37.423633
06-27 01:46:06.708: DEBUG/Test Marker(541): I: 0 X: -122.095897 Y: 37.423633
06-27 01:46:06.708: DEBUG/Test Marker(541): I: 1 X: -122.095897 Y: 37.423633
06-27 01:46:06.708: DEBUG/Test Marker(541): I: 2 X: -122.095897 Y: 37.423633
06-27 01:46:06.708: DEBUG/Test Marker(541): I: 3 X: -122.095897 Y: 37.423633
06-27 01:46:06.718: DEBUG/Test Marker(541): I: 4 X: -122.095897 Y: 37.423633
06-27 01:46:06.718: DEBUG/Test Marker(541): I: 5 X: -122.095897 Y: 37.423633
06-27 01:46:06.728: DEBUG/Test Marker(541): I: 6 X: -122.095897 Y: 37.423633
06-27 01:46:06.739: DEBUG/Test Marker(541): I: 7 X: -122.095897 Y: 37.423633
06-27 01:46:06.739: DEBUG/Test Marker(541): I: 8 X: -122.095897 Y: 37.423633
06-27 01:46:06.739: DEBUG/Test Marker(541): I: 9 X: -122.095897 Y: 37.423633
06-27 01:46:06.748: DEBUG/Test Marker(541): I: 10 X: -122.095897 Y: 37.423633
06-27 01:46:06.748: DEBUG/Test Marker(541): I: 11 X: -122.095897 Y: 37.423633
06-27 01:46:06.748: DEBUG/Test Marker(541): I: 12 X: -122.095897 Y: 37.423633
06-27 01:46:06.748: DEBUG/Test Marker(541): I: 13 X: -122.095897 Y: 37.423633
06-27 01:46:06.758: DEBUG/Test Marker(541): I: 14 X: -122.095897 Y: 37.423633
06-27 01:46:06.758: DEBUG/Test Marker(541): I: 15 X: -122.095897 Y: 37.423633
  • 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-06T20:52:10+00:00Added an answer on June 6, 2026 at 8:52 pm

    Try reinstantiating myCord. It looks like a simple reassignment problem. Pays off to learn about pointers, even with Java!

        do {
            myCoord = new Coord(); //**********
            myCoord.userId = cur.getInt(0);
            myCoord.timestamp = cur.getLong(1);
            myCoord.x = cur.getDouble(2);
            myCoord.y = cur.getDouble(3);
            myCoord.coordType = cur.getInt(4);
            myCoord.id = cur.getInt(5);
            myCoord.coordTypeDesc = cur.getString(6);
            markerArray.add(myCoord);
            Log.d("getCoordMarkers()", "X: " + myCoord.x + " Y: " + myCoord.y);
            myCoord = null; //for the garbage collector *******
        } while( cur.moveToNext());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a function that gets some data from the database and puts
So I have this function that gets data from database and echoes it. The
I have a function that gets some notifications, loops through them and the adds
I have a function that gets filenames from a directory, and then puts them
I have a simple .change function that goes to the database and gets some
In my Java code I have function that gets file from the client in
I have this function in jQuery that gets data from a page with POST,
I have a function that pulls rows from a database, the content->id and content->type
So I have a function in unmanaged c++ that gets called when some text
I have a function that gets response over http. It runs some tests. Lately

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.