# Cannot Create Classes

**URL:** <https://discourse.processing.org/t/cannot-create-classes/8756>\
**Category:** Beginners\
**Created:** [February 27, 2019, 9:24am UTC](https://discourse.processing.org/t/cannot-create-classes/8756 "2019-02-27T09:24:31Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 9:24am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/1 "2019-02-27T09:24:31Z")

</div>

Good morning, people! Recently, I’ve been wresting with one small issue and honestly, it’s really starting to frustrate me. Perhaps it’s a small issue and I’m just going to look stupid, but at this rate, I might as well take the humiliation because I cannot for the life of me figure out why this error keeps popping up.

Basically, I’m trying to just create a class.

Look at the code below:

```auto
let bubble; 

function setup() {
  bubble = new Bubble();
}

function draw() { 
}

class Bubble { //On this line, a Syntax error appears: "Expected an operand, but found class"
  constructor(){
    this.x = random(width);
      } 
}

```

I keep getting “Expected an operand, but found class” as an error and I have no idea why…

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 27, 2019, 10:22am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/2 "2019-02-27T10:22:30Z")

</div>

> [@Martin](#):
>
> class Bubble { //On this line, a Syntax error appears: “Expected an operand, but found class”  
> constructor(){  
> this.x = random(width);  
> }  
> }

should be

```auto
class Bubble { //On this line, a Syntax error appears: “Expected an operand, but found class”
  Bubble(){
    this.x = random(width);
  }
}

```

A constructor is a special mmethod with the same name as the class and no return type

To make your code look like code hichlight it and click on \</\> button. Go back and edit your post to try it 😁

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 10:29am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/3 "2019-02-27T10:29:30Z")

</div>

Oh. Thanks! I was REALLY wondering about that code format thing. Also, thanks for the catch on the constructor naming.

However, I’m still getting the Syntax Error about the program expecting an Operand. At this point, I think I might need to find a way to code without using classes, because this problem is just stumping me hard.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 27, 2019, 10:31am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/4 "2019-02-27T10:31:54Z")

</div>

Are you using Python? The very first line is confusing me, what does it mean.

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 10:42am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/5 "2019-02-27T10:42:49Z")

</div>

It’s one of the many ways I’m trying to define a new class after the usual method returned the same error now. I’m getting desperate here and using things I don’t fully know about such as that first line. XD

Apparently, it should also allow me to declare a new class, but at this point, I don’t fully know.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 27, 2019, 10:51am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/6 "2019-02-27T10:51:19Z")

</div>

Change the first line to

`Bubble bubble;`  
and see what happens.

Do you know what mode you are in pjs, Java, Python???

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 10:55am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/7 "2019-02-27T10:55:16Z")

</div>

Right now I’m in the p5.js mode.  
I tried out your suggestion. It gives me an earlier Syntax Error: “Expected ; but found bubble”

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [February 27, 2019, 11:16am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/8 "2019-02-27T11:16:41Z")

</div>

I think you need to ask someone more familiar with Javascript because I have just tried p5js mode (for the first time) and I am not getting any syntax errors with your original code of with my amended code.

---

<div class="post-metadata">

**Author:** ![hotfooted](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hotfooted/32/3670_2.png) [@hotfooted](https://discourse.processing.org/u/hotfooted)\
**Post date:** [February 27, 2019, 11:43am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/9 "2019-02-27T11:43:25Z")

</div>

@quark your code works here too so it might be something on martins end.

@Martin you don’t have to use classes you could just do something like [this](https://editor.p5js.org/hotfooted/sketches/esR8jThAD)

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 6:28pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/10 "2019-02-27T18:28:02Z")

</div>

@hotfooted  
@quark  
Yeah. Thanks for the help, guys. At this point I have no other choice. It’s probably something up with my computer drives or something messing it up…

---

<div class="post-metadata">

**Author:** ![Californ1a](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/californ1a/32/2648_2.png) [@Californ1a](https://discourse.processing.org/u/Californ1a)\
**Post date:** [February 27, 2019, 6:28pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/11 "2019-02-27T18:28:32Z")

</div>

What are you using to do the coding? Processing in p5js mode, p5js web editor, or a local sketch.js and index.html?

What browser are you using to view the sktech? And what version number of that browser?

It’s not ideal to have to use old prototypes in place of classes.

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 6:30pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/12 "2019-02-27T18:30:11Z")

</div>

I’m using the p5.js mode of the processing program and whenever I do get to run it, it is using Chrome.

---

<div class="post-metadata">

**Author:** ![Californ1a](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/californ1a/32/2648_2.png) [@Californ1a](https://discourse.processing.org/u/Californ1a)\
**Post date:** [February 27, 2019, 6:39pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/13 "2019-02-27T18:39:00Z")

</div>

What version of chrome? As long as you’re using a version newer than chrome 49, then classes should work (that’s from early 2016, so it’s probably safe to assume your chrome has been updated since then but you should check just in case).

Could you try using a text editor with local sketch.js and index.html files and following this?:

[![](https://img.youtube.com/vi/HZ4D3wDRaec/maxresdefault.jpg "1.2: p5.js Workflow - p5.js Tutorial") ](https://www.youtube.com/watch?v=HZ4D3wDRaec)

Edit: Sorry that was an older video, I’ve replaced it with the updated one now^^

---

<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:** [February 27, 2019, 8:12pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/14 "2019-02-27T20:12:02Z")

</div>

> [@Code 800A0404 issue](https://discourse.processing.org/t/code-800a0404-issue/2036/3):
>
> Easiest & fastest recipe to run “.js” sketches under p5.js: running_man Install any Firefox-based browser in your OS and use it to open your “index.html” file: fox_faceInstall Notepad2 or Notepad++ (or both) in your OS and use it to type in your “sketch.js” file there: scroll[https://XhmikosR.GitHub.io/notepad2-mod/](https://XhmikosR.GitHub.io/notepad2-mod/)[https://Notepad-Plus-Plus.org](https://Notepad-Plus-Plus.org) You can setup those text editors to use UTF-8 and LF line endings for better compatibility. bulbHere’s my minimum “index.html” te…

---

<div class="post-metadata">

**Author:** ![Martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@Martin](https://discourse.processing.org/u/Martin)\
**Post date:** [February 27, 2019, 9:49pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/15 "2019-02-27T21:49:38Z")

</div>

It’s not the browsers that messing up the code. Rather I open it through the HTML index or run it in the Pde, the program will still give me that error. At this point, I think it may be the way my JDK or JRE is set up.

What version of the p5.js, JRE, and JDK is everyone else using currently to run p5 programs?

---

<div class="post-metadata">

**Author:** ![Californ1a](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/californ1a/32/2648_2.png) [@Californ1a](https://discourse.processing.org/u/Californ1a)\
**Post date:** [February 28, 2019, 4:45am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/16 "2019-02-28T04:45:22Z")

</div>

JRE and JDK are irrelevant to p5. You only need them for processing. If they are causing issues, then the best solution is to move out of processing to work with p5 by using a local webserver as described in the video I linked previously. You can also use the method @GoToLoop posted, but that doesn’t use a webserver and may also cause some issues depending on what your code is doing (which is mentioned in the video).

---

<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:** [March 1, 2019, 11:41am UTC](https://discourse.processing.org/t/cannot-create-classes/8756/17 "2019-03-01T11:41:38Z")

</div>

> [@Californ1a](#):
>
> You can also use the method @GoToLoop posted, but that doesn’t use a webserver and may also cause some issues depending on what your code is doing (which is mentioned in the video).

AFAIK, Firefox-based browsers treat the `file://` URL scheme the same way as the `http://` URL scheme. 🦊

Thus far I haven’t found any issues at all when running Processing sketches on Firefox under its `file://` URL scheme. 🥳

Firefox-based browsers use the Gecko Spidermonkey JS engine. 🕷

But if we prefer/need to test JS on the Chrome’s Blink V8 engine instead, we can use the Vivaldi browser: 🎼

> **[Vivaldi Browser | Powerful, Personal and Private web browser](https://vivaldi.com)**
>
> It’s a web browser. But fun. It comes with a bunch of clever features built-in. It’s super flexible and does not track you. Get the Vivaldi browser for desktop, mobile, and your car!

Similarly to Firefox, Vivaldi doesn’t restrict the `file://` URL scheme either. 👌

However, anything that relies on the Fetch API fails on the V8 JS engine, b/c they’ve deliberately disallowed the `file://` URL scheme on this particular API: 🤬

[Bugs.Chromium.org/p/chromium/issues/detail?id=810400](http://Bugs.Chromium.org/p/chromium/issues/detail?id=810400)

---

<div class="post-metadata">

**Author:** ![Rolembeek](https://avatars.discourse-cdn.com/v4/letter/r/47e85d/32.png) [@Rolembeek](https://discourse.processing.org/u/Rolembeek)\
**Post date:** [May 7, 2019, 9:16pm UTC](https://discourse.processing.org/t/cannot-create-classes/8756/18 "2019-05-07T21:16:57Z")

</div>

As I have exactly the same problem I tried the mod of the code but get same error.  
Strange enough, when I use the same code (with “Constructor” keyword) in the web editor everything works fine ! In the “local” mode I have to use the keywords “Function” and declare accordingly.  
Anny sugestion ?
