We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I am trying to get an array from inside a library class, but the field is set as private :((
I used a java decompiler website to see this source of code:
public class MultiMarker
extends NyARPsgBaseClass {
protected PImageSensor _ss;
protected NyARMarkerSystem _ms;
public static final double DEFAULT_CF_THRESHOLD = 0.51;
public static final int DEFAULT_LOST_DELAY = 10;
public static final int THLESHOLD_AUTO = -1;
private ArrayList<Integer> _id_map = new ArrayList(); //<<------- I WANT TO ACCESS THIS
private final PMatrix3D _ps_projection = new PMatrix3D();
private boolean _is_in_begin_end_session = false;
So this is what I had tried following some examples using Java as reference but still variable is NOT VISIBLE. maybe some casting problem...
import java.lang.reflect.*;
import jp.nyatla.nyar4psg.*;
MultiMarker nya;
void setup() {
size(640,360);
nya=new MultiMarker(this, 640, 360, "camera_para.dat", NyAR4PsgConfig.CONFIG_PSG);
nya.addARMarker("patt.hiro", 80);//id=0
nya.addARMarker("patt.kanji", 80);//id=1
try {
MultiMarker.class.getDeclaredField("_id_map").setAccessible(true);
//or
//Field idmap = MultiMarker.class.getDeclaredField("_id_map");
//idmap.setAccessible(true);
// ArrayList<Integer> castTest = idmap.get( ArrayList<Integer>() ); //--error
// ArrayList<Integer> castTest = (ArrayList<Integer>)idmap.get(idmap); //--error
}
catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
println(nya._id_map.size()); //field is not visible
}
Answers
https://forum.Processing.org/two/discussion/9412/how-to-find-a-row-in-a-table
https://forum.Processing.org/two/discussions/tagged?Tag=setaccessible()
Yes, so I have read these examples and tried to implement in the code above. I have read the reflect.class documentation and I believe maybe the problem is how I am trying to retrieve the ArrayList object using the Field.get( obj ).
But no. I have tried to access a private boolean variable using Field.getBoolean(obj) but I got "Can not set boolean field jp.nyatla......MultiMarker._is_in_begin_end_session to java.lang.reflect.Field" error
So it wasn't a casting problem as I expected...
Gonna try to implement a more general approach and post it here when ready. :-h
Thank you GoToLoop!! Got it working finally. Problem was using wrong object inside the Field.get method. #-o
@bontempos, congratz for solving it alone. <:-P
Nonetheless, gonna leave the general solution here as reference for others: O:-)