1

I'm trying to fetch a list from MySQL on android but I'm getting

[com.trycatchsoft.app.Models.KatPojo@7553fa]

as output instead of list.

Here is my pojo file:

package com.trycatchsoft.app.Models;

public class KatPojo {

  private Boolean tf;
  private String veri;
  private String verid;

  public Boolean getTf() {
      return tf;
  }

  public void setTf(Boolean tf) {
      this.tf = tf;
  }

  public String getVeri() {
      return veri;
  }

  public void setVeri(String veri) {
      this.veri = veri;
  }

  public String getVerid() {
      return verid;
  }

  public void setVerid(String verid) {
      this.verid = verid;
  }
}
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
ebu
  • 11
  • 2
  • 4
    That's the default `toString()` representation of an object . How are you using the Object ? Override it if you want to print the contents . https://stackoverflow.com/questions/10734106/how-to-override-tostring-properly-in-java – ADM Jan 04 '21 at 04:42
  • thanks a lot my friend. i added public String toString() { return veri; } to my pojo file and now i can see my array. thank you again – ebu Jan 04 '21 at 04:47
  • yes it answered my question. the first answer was very helpful – ebu Jan 04 '21 at 04:53

3 Answers3

0

By default, printing an Object results in a class name and hash code. One can change this result by overriding the toString() method inherited by all children of Object.

Adrian Russo
  • 546
  • 4
  • 16
  • thanks. i added public String toString() { return veri;} to end of my pojo file and now it returns my array – ebu Jan 04 '21 at 04:55
0

When you're working with the Object type, you need to override the toString() method and call this method if you want to get the string representation of this object.

Nam V. Do
  • 630
  • 6
  • 27
0

you can also use https://github.com/google/gson If you are debugging I find it easy to just print the json instead of writing toString. You can pass your object or an array of objects.

Gson GSON = new GsonBuilder().setPrettyPrinting().create();
System.out.println(GSON.toJson(<PASS YOUR OBJECT REFERENCE HERE>));
A Paul
  • 8,113
  • 3
  • 31
  • 61