0

I add to my ArrayList "activList" elements using:

activList.add(new Fiducial("R600" ));

And I print it using:

System.out.println(activList);

Here is the code:

// Grid variables
int cols = 10, rows = 10;
int rectangleWidth = 100;
int rectangleHeight = 60;

// these are some helper variables which are used
// to create scalable graphical feedback
int k, l, iD;
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
float x, y;


ArrayList<Fiducial> activList = new ArrayList<Fiducial>();

public class Fiducial {

  public String type;

  public Fiducial(String type) {

    this.type = type;
  }

}

void draw() {
  // Begin loop for columns
  for ( k = 0; k < cols; k++) {
    // Begin loop for rows
    for ( l = 0; l < rows; l++) {
      fill(255);
      stroke(0);
      rect(k*rectangleWidth, l*rectangleHeight, rectangleWidth, rectangleHeight);
    }
  }




  // This part detects the fiducial markers 
  float obj_size = object_size*scale_factor; 
  float cur_size = cursor_size*scale_factor; 

  ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
  for (int i=0; i<tuioObjectList.size (); i++) {
    TuioObject tobj= tuioObjectList.get(i);
    stroke(0);
    fill(0, 0, 0);
    pushMatrix();
    translate(tobj.getScreenX(width), tobj.getScreenY(height));
    rotate(tobj.getAngle());
    rect(-80, -40, 80, 40);
    popMatrix();
    fill(255);
    x = round(10*tobj.getX ());
    y = round(10*tobj.getY ());
    iD = tobj.getSymbolID();
    activList.add(new Fiducial("R600" ));
    fiducialVisibles ();

  }

}


void fiducialVisibles () {
System.out.println(activList);
}

However, it returns something like [FiducialDetection$Fiducial@47baec4c] which seems to be the address. How can I retrieve the actual value of the string ?

Graham Slick
  • 6,692
  • 9
  • 51
  • 87

2 Answers2

2

Implement toString() on your Fiducial class.

1
public class Fiducial { 

    @Override
    public String toString() {
        String yourResult = this.type; // + ...
        return yourResult;
    }

}

You must override toString() method in your class.

Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142