# The function "red(int)" does not exist?

**URL:** <https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567>\
**Category:** Beginners\
**Created:** [June 9, 2024, 3:09pm UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567 "2024-06-09T15:09:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![flice](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@flice](https://discourse.processing.org/u/flice)\
**Post date:** [June 9, 2024, 3:09pm UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/1 "2024-06-09T15:09:36Z")

</div>

hello!  
i have the code below to keep sum the rbg values every 16 pixels. However, i’m getting an error saying that red(int), green(int), and blue(int) does not exist?? the argument i passed into the function is a color, so it should work. please help, thank you so much!

```auto
public void averageColor(PImage img) {
    for (int i = 0; i < emojiNames.size(); i++) {
      Integer[] Color = new Integer[3];
      int times = 0;
      for (int r = 0; r < img.width; r += 16) {
        for (int c = 0; c < img.height; c += 16) {
          color currentColor = img.get(r, c);
          Color[0] += (int) red(currentColor);
          Color[1] += (int) green(currentColor);
          Color[2] += (int) blue(currentColor);
          times++;
        }
      }
      Color[0] = Color[0]/times;
      Color[1] = Color[1]/times;
      Color[2] = Color[2]/times;
      colorList.add(Color);
    }
  }

```

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 9, 2024, 3:37pm UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/2 "2024-06-09T15:37:53Z")

</div>

Hello @flice,

Your _Integer_ array (objects) is not initialized (contains _null_ elements) and you can’t add to a value in there.

Try an _int_ array (initialized to 0) instead of _Integer_ (_null_ values initially).

Try this:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/b/1/b1d7ac6c216aea6e5a96af8aa027c1bda2e3b916.png)

Reference:

> **[Difference between an Integer and int in Java with Examples - GeeksforGeeks](https://www.geeksforgeeks.org/difference-between-an-integer-and-int-in-java/)**
>
> A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions.

> **[Complete Guide: How to Initialize an Array in Java with Values](https://xperti.io/blogs/initialize-an-array-in-java-with-values/)**
>
> Master Java array initialization with diverse methods and advanced techniques. Enhance your coding skills and efficiency today! Learn more.

`:)`

---

<div class="post-metadata">

**Author:** ![flice](https://avatars.discourse-cdn.com/v4/letter/f/eada6e/32.png) [@flice](https://discourse.processing.org/u/flice)\
**Post date:** [June 9, 2024, 11:12pm UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/3 "2024-06-09T23:12:59Z")

</div>

unfortunately it still doesn’t seem to work… the error is still there 😭

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/8/4/84281ee36d275b05f634fbc29335745d2ae646c0.png)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 10, 2024, 1:32am UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/4 "2024-06-10T01:32:59Z")

</div>

OR you incidentally wrote a function that has the name red() elsewhere?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [June 10, 2024, 1:34am UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/5 "2024-06-10T01:34:55Z")

</div>

Also, try rename Color to colorList

Looks suspicious

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 10, 2024, 6:47am UTC](https://discourse.processing.org/t/the-function-red-int-does-not-exist/44567/6 "2024-06-10T06:47:52Z")

</div>

> [@flice](#):
>
> unfortunately it still doesn’t seem to work… the error is still there 😭

There are other problems in the list (in the image) you provided and you did not share the related code.  
Once you correct the existing problems you will see other problems and that is where my post will help.

_[Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147#is-your-problem-isolated-4)_ \< Can you post an MCVE?

The code below works with Processing 4.3 on W10 and does not report any problems.

Try this (your code with additions by me) and report the result on your end:

```auto
import java.util.*;
// If using int:
List<int[]> cl = new ArrayList<int[]>();

// If using Integer:
//List<Integer[]> cl = new ArrayList<Integer[]>(); // If using Integer

//PImage sf;

void setup()
  {
  size(200, 200);  
  PImage sf = loadImage("http://learningprocessing.com/code/assets/sunflower.jpg");
  averageColor(sf);
  noLoop();
  }

public void averageColor(PImage img) 
  {
  for (int i = 0; i < 3; i++) 
    {
    // If using int:
    int [] Color = new int[3];
    
    // If using Integer:
    //Integer[] Color = new Integer[3];    
    //for(int j=0; j<3; j++)
    // {
    // Color[j] = 0;
    // }
 
    int times = 0;    
    
    for (int r = 0; r < img.width; r += 16) 
      {
      for (int c = 0; c < img.height; c += 16) 
        {
        color currentColor = img.get(r, c);
        Color[0] += (int) red(currentColor);
        Color[1] += (int) green(currentColor);
        Color[2] += (int) blue(currentColor);
        times++;
        }
      }
    Color[0] = Color[0]/times;
    Color[1] = Color[1]/times;
    Color[2] = Color[2]/times;
    cl.add(Color);
    printArray(cl.get(i));
    //println(hex(cl.get(i)[0]), hex(cl.get(i)[1]), hex(cl.get(i)[2]));
    }
  }

```

What version of Processing are you using?  
What operating system?

`:)`
