Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] Android Studio: Unable to print cursor results

Posted on November 11, 2022 By

Solution 1 :

Your output is:

D/Row values: [email protected]

That would make sense if:

  • rowValuesList contains a single Todo object, and
  • Your Todo class does not have a custom implementation of toString()

The default implementation of toString() that you inherit from Object gives a result like what you see: the fully qualified class name and an object ID, separated by @.

Problem :

I am attempting to print the cursor results to log.d.

When I print the results of the cursor, it does not print the array.

i.e. D/Row values: [email protected]

Here is the code:

  public void printCursor(Cursor c) {
        //The database version number using db.getVersion for the version number.
        int version = db.getVersion();

        //The number of rows in the cursor
        int rowCount = c.getCount();

        //The number of columns in the cursor
        int columnCount = c.getColumnCount();

        //The names of the columns in the cursor
        String[] columnNames = c.getColumnNames();

        //The results of each row in the cursor
        ArrayList<Todo> rowValuesList = new ArrayList<>();

        int ColIndex = c.getColumnIndex(myOpener.COL_1);
        int itemColIndex = c.getColumnIndex(myOpener.COL_2);
        int urgentColIndex = c.getColumnIndex(myOpener.COL_3);

        c.moveToFirst();

        if(c.moveToFirst()) {

                long id = c.getLong(ColIndex);
                String item = c.getString(itemColIndex);
                int urgentInt = c.getInt(urgentColIndex);

                if (urgentInt == 1) {
                    urgent = true;
                } else {
                    urgent = false;
                }

                rowValuesList.add(new Todo(item, urgent, id));
        }

        String rowValues = TextUtils.join(",", rowValuesList);

        //Printing variables to log
        Log.d("Database version", String.valueOf(version));
        Log.d("Row count", String.valueOf(rowCount));
        Log.d("Column count", String.valueOf(columnCount));
        Log.d("Column names", Arrays.toString(columnNames));
        Log.d("Row values", rowValues);

    }

Other options I have tried that have not worked:

Log.d("Row values", rowValuesList.toString());
 for (Todo t : rowValuesList) {
            Log.d("Row values", String.valueOf(t));
        }
StringBuilder s = new StringBuilder();
        for(Todo todo : rowValuesList) {
            s.append(todo);
            s.append(",");
        }
        Log.d("Row values", String.valueOf(s));

I know the cursor is not empty as it is displays the results when loaded from SQLite on the application.

Any advice would be helpful.

READ  [FIXED] android - How to ask user to turn on location
Powered by Inline Related Posts

Thank you,

Comments

Comment posted by CommonsWare

“When I print the results of the cursor, it does not print the array” — then, what does it print? If you use the debugger, what is in your

Comment posted by a

That is expected, if

Android Tags:android, android-cursor, android-studio, arraylist

Post navigation

Previous Post: [FIXED] android – W/Firestore: (24.1.2) [CustomClassMapper]: No setter/field for about found on class
Next Post: [FIXED] android – FusedLocationProviderClient and LocationCallback() object queries

Related Posts

[FIXED] Kotlin: Count No of occurrences of string in string Android
[FIXED] reactjs – Couldn’t start project on Android: Error running adb: This computer is not authorized to debug the device Android
[FIXED] android – Room database Pre-packaged database has an invalid schema Android
[FIXED] android – Cant change label title with NavigationComponents Android
[FIXED] android – APK makes two files Android
[FIXED] kotlin – Android Room [SQLITE_ERROR] SQL error or missing database when using Relation and Junction Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • Which is stronger 19 gauge or 23 gauge?
  • Does BMW still use GM transmissions?
  • Is primary or secondary market research better?
  • What does it mean when ADT says low battery?
  • Can a baby sleep on a regular mattress?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme