edited November 2017 in Questions about Code


I have a code that is suposed to work, but it has an error "Cannot find anything named Array" in line 9

 import java.util.HashSet;
Integer[] getPalette(PImage img){
HashSet<Integer> colours = new HashSet<Integer>();
for(int p : img.pixels){
  colours.add(new Integer(p));
Integer[] p = colours.toArray(new Integer[colours.size()]);
return p;  

void colour (PImage img, Integer p[]){
  Integer c;
  float distance;
  float mindistance = 1000000;
  Integer closest=0;   
  //colors.add (new ObjectColor (theimage.get(1,1)));
  for (int i = 1; i < img.width; i++){
    for (int j = 1; j < img. height; j++){
  //println (i+"         "+j);      
      c= img.get(i,j);
      //found = false;
      for (int k = 0; k < p.length; k++){

        distance = sq(red(p[k])-red(c)) + sq(green(p[k])-green(c)) + sq(blue(p[k])-blue(c));
        if (distance < mindistance){  
          closest = p[k];


  • Line 9:


    Where is Arrays defined?

  • edited November 2017 Answer ✓

    Need to add

    import java.util.Arrays;

  • Thank you, Its strange because I remember Ive used this code years ago, and it worked and now I have to add this

  • edited November 2017

    Processing uses a pre-proccessor to convert the Sketch code to pure Java. Newer versions have reduced the number of imports added.

  • Bad idea I think, because processing is good to start. To learn. If you have to add imports, this is more difficult to understand

  • edited November 2017

    Well, I see what you mean, but you can also sort an array without importing Array...

    ...or you can use the no-import ArrayList or one of the types like IntList, StringList etc. all of which have a .sort() I'm not sure that a Processing 3 beginner doesn't really have options here for sorting an array without importing.

Sign In or Register to comment.