# Why cannot find a class or type named "Box"

**URL:** <https://discourse.processing.org/t/why-cannot-find-a-class-or-type-named-box/36596>\
**Category:** Libraries\
**Tags:** homework\
**Created:** [April 26, 2022, 1:46am UTC](https://discourse.processing.org/t/why-cannot-find-a-class-or-type-named-box/36596 "2022-04-26T01:46:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiajia](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jiajia/32/16099_2.png) [@jiajia](https://discourse.processing.org/u/jiajia)\
**Post date:** [April 26, 2022, 1:46am UTC](https://discourse.processing.org/t/why-cannot-find-a-class-or-type-named-box/36596/1 "2022-04-26T01:46:41Z")

</div>

```auto
import shiffman.box2d.*;

ArrayList<Box>boxes;
PBox2D box2d;

void setup(){
  size(400,300);
  boxes = new ArrayList<Box>();
  box2d = new PBox2D(this);
  box2d.createWorld();
}

void draw(){
  box2d.step();
  background(255);
  if(mousePressed){
    Box p = new Box(mouseX,mouseY);
    boxes.add(p);
  }
  for(Box b:boxes){
    b.display();
  }
}

class Box{
  Body body;
  float w,h;
  
  Box(){
    w=16;
    h=16;
   
  BodyDef bd = new BodyDes();
  bd.type = BodyType.DYNAMIC;
  bd.position.set(box2d.coordPixelsToWorld(mouseX,mouseY));
  body = box2d.createBody(bd);
  
  PolygonShape ps = new PolygonShape();
  
  float box2dw = box2d.scalarPixelsToWorld(w/2);
  float box2dh = box2d.scalarPixelsToWorld(h/2);
  
  ps.setAsBox(box2dw,box2dh);
  
  FixtureDef fd = new FixtureDef();
  fd.shape = ps;
  fd.density = 1;
  fd.friction = 0.3;
  fd.restitution = 0.5;
  body.createFixture(fd);
 }

  
  void display(){
    Vec2 pos = box2d.getBodyPixelCoord(body);
    float a = body.getAngle();
    pushMatrix();
    translate(pos.x,pos.y);
    rotate(-a);
    fill(175);
    stroke(0);
    rectMode(CENTER);
    rect(0,0,w,h);
    popMatrix();
}

void killBody(){
  box2d.destroyBody(body);
}
}

```

 ![屏幕截图 2022-04-25 221130](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/a/2/a2d668d53e1f0db850ce7dff33b41861bdc8b513.jpeg)

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [April 28, 2022, 4:23am UTC](https://discourse.processing.org/t/why-cannot-find-a-class-or-type-named-box/36596/2 "2022-04-28T04:23:59Z")

</div>

> [@jiajia](#):
>
> ```auto
> class Box{
> Body body;
> float w,h;
>   
> Box(){
> 
> ```

You define constructor without parameters, but you use constructor `new Box(mouseX,mouseY)` two parameters. That causes the error.
