# Objects and class objects cannot be converted?

**URL:** https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276
**Category:** Beginners
**Created:** [January 23, 2020, 5:05am UTC](https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276 "2020-01-23T05:05:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Edudmas](https://avatars.discourse-cdn.com/v4/letter/e/a9a28c/32.png) [@Edudmas](https://discourse.processing.org/u/Edudmas)
#### Post date: [January 23, 2020, 5:05am UTC](https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276/1 "2020-01-23T05:05:26Z")

</div>

I don’t want to muck up the page, so there will be a pastebin at the bottom with my code on it.

I am trying to create a HashMap and create multiple objects of a ‘Car’ class depending on the variable entered into my ‘Traffic’ class. But I get an error on line 28 saying “Type mismatch: cannot convert to Object to traffic.Car.” How do I solve this issue?

Traffic class: [https://pastebin.com/yyFsnEhn](https://pastebin.com/yyFsnEhn)  
Car class: [https://pastebin.com/pUq8rLMg](https://pastebin.com/pUq8rLMg)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [January 23, 2020, 5:50am UTC](https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276/2 "2020-01-23T05:50:36Z")

</div>

Replace `private Map cars = new HashMap();`  
w/ `final Map<String,Car> cars = new HashMap<String,Car>();`

> [@2D Array of TreeMaps wont access the intValue()](https://discourse.processing.org/t/2d-array-of-treemaps-wont-access-the-intvalue/17245/2):
>
> If you know how many you’re gonna need, you can simplify things a lot by choosing a vanilla array. You didn’t specify the generic datatypes for your TreeMap: Which seems like it is the pair color & int. So, their corresponding wrapper type is Integer: final TreeMap\<Integer, Integer\>[] colourRanges = new TreeMap[7];

---

<div class="post-metadata">

### Author: ![Edudmas](https://avatars.discourse-cdn.com/v4/letter/e/a9a28c/32.png) [@Edudmas](https://discourse.processing.org/u/Edudmas)
#### Post date: [January 23, 2020, 12:17pm UTC](https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276/3 "2020-01-23T12:17:50Z")

</div>

Thanks! I am trying to make it so that the quantity of the Car objects are controlled by a single variable from the traffic class.

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [January 23, 2020, 10:55pm UTC](https://discourse.processing.org/t/objects-and-class-objects-cannot-be-converted/17276/4 "2020-01-23T22:55:21Z")

</div>

> [@Edudmas](#):
>
> I don’t want to muck up the page

FYI, you can embed code blocks of any length, and they will become scrollable and syntax highlighted as long as you [format your code](https://discourse.processing.org/faq#format-your-code).
