Hi, I am pretty new to processing and I'm having problems with a 2d string array. Originally I wanted to use append() to add each line to the end parsedcode as they are processed but the string array parsedline was showing up as an object instead, so couldn't be added. The reference entry for append has this
"When using an array of objects, the data returned from the function must be cast to the object array's data type. For example:
SomeClass[] items = (SomeClass[]) append(originalArray, element)."
but I don't really understand what it means amd cant figure out how to cast an object as an array.
Anyway I then switched it to an arraylist but I still have the same issue when I try to pull data back into an array.
Here is the relevant function, I can post more if needed.
The error is at the end, when I try to create the array tosave. (cannot convert from Object[] to String[])
void buildarrays() { for(int line = 0; line < gcode.length; line++) { //Split each line up at spaces and put the elements in an array for parsing String[] rawline = splitTokens(gcode[line], " "); //The result goes in here(initializes with the shift-\ character so we can detect empty entries) String[] parsedline = {"|", "|", "|", "|", "|", "|", "|", "|", "|", "|"}; //Element counters for raw and parsed arrays int r = 0; int p = 0; int s = 9;
//println("+++++++"); //Go through each element of the raw line while ( r < rawline.length) { //println("Trim"); //remove white space rawline[r] = trim(rawline[r]);
//If a "(" or "%" is found end the line if ((rawline[r].charAt(0) == '(') || (rawline[r].charAt(0) == '%')) { //println("Comment"); r = rawline.length; }
//If an element is one char long, merge it with the next element (if there is one) else if ((rawline[r].length() == 1) && (r < rawline.length)) { //println("Merge"); String[] tojoin = {rawline[r], rawline[r + 1]}; parsedline[p] = join(tojoin, ""); p++; r++; r++; }
//Or just copy it over else { //println("Copy"); parsedline[p] = rawline[r]; p++; r++; } }
//Trim off the empty elements of parsed line //Need to add handling for lines with no usefull info while (parsedline[s].charAt(0) == '|' && s > 0) { //println("Shorten"); parsedline = shorten(parsedline); s--; } //println(parsedline.length);