So, I’ve been looking at this code for the past couple hours, and I can’t for the life of me figure out what’s going on.
Please note: For the sake of keeping things simple, I didn’t list the contents of the array sizeindex (with a length of 95). If you think seeing its contents might be useful, just tell me.
int[] sizeindex={/*An extremely long array right here. I've tried shortening it to see if that was the problem, but nothing changed.*/};
float getWidth(int Code, float txSize) { //this returns the width of a character given its Unicode expression (to those reading who are curious, the array only works for Unicode between 32 and 126)
return (sizeindex[Code-32]*txSize)/80.0; //find the size index, multiply by the text size, divide by 80 (I added the divide by 80 part because I didn't want to suck up too much memory with an array of 95 floats)
}
And then, in another tab, I have a class called button. This is its constructor
button(float x1, float y1, float wdth, float hgt, float ra, color col1, color col2, color col3, String txt, float txsz, boolean texed, int spec, String inpu) { //this is our constructor
boxx=x1; boxy=y1; wid=wdth; hig=hgt;
txcol=col1; boxcol=col2; backcol=col3;
rad=ra;
text=txt; txsiz=txsz;
txed=texed; spc=spec; inp=inpu;
siz=0;
for(int n=0;n<inpu.length();n++) {
println(n); //this line was here to debug. If it helps, the code returned a 0 before it gave me the error message
siz+=getWidth(int(inpu.charAt(n)), 20.0);
}
lum=0.25;
lum2=0.25;
vis=true;
parent=pNull;
}
My problem is, once I introduced the getWidth function into the constructor, I received an error that looks like this:
java.lang.reflect.InvocationTargetException
I tried removing certain snippets of code selectively, until I concluded that getWidth’s reference to sizeindex is what’s causing the issue. getWidth seems to work outside of this constructor, but not inside. Not unless I remove the reference to sizeindex and instead tell it to return, say, 0. If I do that, then the code works without so much as a stutter.
My question is this: Why can I not access sizeindex inside this constructor? From what I can tell, it should be a global variable. If that’s not the case, or if classes are very picky about how global a variable can be, what do I do to fix this issue?
Help would be much appreciated. Thank you!
P.S. I don’t know if you’ll find this information useful, but I tried removing the call to getWidth in the constructor and replacing it with println(sizeindex[0]); I got the same error about reflect invocation.