0
List<color> cr = new ArrayList<color>(); 

Why does the above code show me Error on Dimensions?

3
  • Without knowing what you want to do, or without having at least a snippet of runnable code, it's hard to help. The question becomes too broad to answer. It seems like ArrayList accepts objects only, and colour is not a valid one. I would suggest you create a class, with inside an object that has all the values you need to store in the ArrayList and use that instead as the ArrayList object! Commented Jun 22, 2017 at 9:31
  • I want to initial a set of custom objects' color. I must create a new class instead of using the already existing datatype(color) in processing? Commented Jun 22, 2017 at 10:43
  • Exactly. If you have a look at this question, you'll see that a new class, with a new object is created to assign a different colour to every circle drawn on screen. Once you've tried, if you're still struggling, edit the question to make it less broad. Commented Jun 22, 2017 at 10:50

1 Answer 1

4

Use Integer instead of color:

import java.util.*; List<Integer> cr = new ArrayList<Integer>(); //populate list for(int i = 0 ; i < 100; i++){ cr.add(color(random(255),random(255),random(255))); } //retrieve values from list for(int i = 0 ; i < 100; i++){ fill(cr.get(i)); rect(i % 10 * 10, i / 10 * 10,10,10); } 

Why ?

ArrayList can only reference types, not primitives. Integer is a class, not a primitive.

More details in this answer

In this case the color datatype is a primitive.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.