# I dont know why it keep saying NullPointerException

**URL:** <https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134>\
**Category:** Coding Questions\
**Created:** [May 17, 2021, 2:48pm UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134 "2021-05-17T14:48:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [May 17, 2021, 2:48pm UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/1 "2021-05-17T14:48:37Z")

</div>

```auto

PVector A, B, C, D;
float s = 100;
int binary = 0;
Boom c;

void setup() {
  size(640, 640);
  background(255);
  drawrect();
  c = new Boom(A,B,C,D);
}

void draw() {
  c.testmousepos();
  c. getEpos () ;
  
  if (mousePressed) {
    //background(255);
  }
}

void drawrect() {
  A = new PVector (random(width/2-s, width/2+s), random(height/2-s, height/2+s));
  B = new PVector (A.x+random(s*2), random(height/2-s, height/2+s));
  if (A.y>B.y) {
    C = new PVector (A.x+random(s*2), A.y+random(s*2));
    D = new PVector (C.x-random(s*2), A.y+random(s*2));
  } else {
    C = new PVector (A.x+random(s*2), B.y+random(s*2));
    D = new PVector (C.x-random(s*2), B.y+random(s*2));
    //println(A, B, C, D);
  }

  beginShape();
  vertex(A.x, A.y);
  vertex(B.x, B.y);
  vertex(C.x, C.y);
  vertex(D.x, D.y);
  endShape(CLOSE);
}

class Boom {

  PVector La1, La2, Lb1, Lb2;
  boolean mouseinside ;
  PVector E = new PVector(mouseX, mouseY);
  PVector E2 =E;
  PVector E3 =E;
  PVector E4 =E;

  Boom(PVector tempLa1, PVector tempLa2, PVector tempLb1, PVector tempLb2 ) {
    tempLa1=La1;
    tempLa2=La2;
    tempLb1=Lb1;
    tempLb2=Lb2;
  }

  void testmousepos() {
    testintersect( La1, La2, E);
    testintersect( La2, Lb1, E);
    testintersect( Lb1, Lb2, E);
    testintersect( Lb2, La1, E);

    if (binary == 2 || binary == 4 ) {
      mouseinside = true;
    } else {
      mouseinside = false;
    }
  }

  void getEpos () {
    if (mousePressed&&mouseinside) {
      beginShape(TRIANGLE);
      vertex(La1.x, La1.y);
      vertex(La2.x, La2.y);
      vertex(E.x, E.y);

      endShape(CLOSE);
    }
  }

  void testintersect(PVector L1, PVector L2, PVector pos) {

    float x1 = L1.x;
    float y1 = L1.y;
    float x2 = L2.x;
    float y2 = L2.y;

    float x3 = pos.x;
    float y3 = pos.y;
    float x4 = 0;
    float y4 = 0;

    float den = (x1-x2) * (y3-y4) - (y1-y2) * (x3-x4);
    if (den == 0) {
      return;
    }
    float t = ((x1-x3) * (y3-y4) - (y1-y3) * (x3-x4)) / den;
    float u = - ((x1-x2) * (y1-y3) - (y1-y2) * (x1-x3)) / den;
    if (t > 0 && t < 1 && u > 0) {
      binary +=1;
    }

  }
}

```

and why it shows me the value of the parameter temLa1 is not used

 ![65d85503c46326c94eee660e7edb259](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/9/9b191a0d5644dd3041d828afb8de5a9bcb3d4ecb.png)  
 ![99094fb27388ab27bd403d112728e46](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/b572b9db94b4f64479136735e0fae7766f4c66ee.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:** [May 17, 2021, 2:51pm UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/2 "2021-05-17T14:51:06Z")

</div>

////

edited

I was wrong

---

<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:** [May 17, 2021, 2:53pm UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/3 "2021-05-17T14:53:05Z")

</div>

> [@zang](#):
>
> `tempLa1=La1;`

You want La1=tempLa1;

what you want to define is left of the =

Next: You use L1; do you mean La1?

my version

```auto

PVector A, B, C, D;
float s = 100;
int binary = 0;

Boom c;

// -----------------------------------------------------------------------------------------------

void setup() {
  size(640, 640);
  background(255);
  drawrect();
  c = new Boom(A, B, C, D);
}

void draw() {
  c.testmousepos();
  c.getEpos();

  if (mousePressed) {
    //background(255);
    //getEpos() ;
  }
}

// -----------------------------------------------------------------------------------------------

void drawrect() {
  A = new PVector (random(width/2-s, width/2+s), random(height/2-s, height/2+s));
  B = new PVector (A.x+random(s*2), random(height/2-s, height/2+s));
  if (A.y>B.y) {
    C = new PVector (A.x+random(s*2), A.y+random(s*2));
    D = new PVector (C.x-random(s*2), A.y+random(s*2));
  } else {
    C = new PVector (A.x+random(s*2), B.y+random(s*2));
    D = new PVector (C.x-random(s*2), B.y+random(s*2));
    //println(A, B, C, D);
  }

  beginShape();
  vertex(A.x, A.y);
  vertex(B.x, B.y);
  vertex(C.x, C.y);
  vertex(D.x, D.y);
  endShape(CLOSE);
}

//============================================================================================

class Boom {

  PVector La1, La2, Lb1, Lb2;
  boolean mouseinside = false;
  PVector E = new PVector(mouseX, mouseY); // won't work here
  PVector E2 = E;
  PVector E3 = E;
  PVector E4 = E;

  Boom(PVector tempLa1, PVector tempLa2, PVector tempLb1, PVector tempLb2 ) {
    La1=tempLa1.copy();
    La2=tempLa2.copy();
    Lb1=tempLb1.copy();
    Lb2=tempLb2.copy();

    //tempLa2=La2;
    //tempLb1=Lb1;
    //tempLb2=Lb2;
  }

  void testmousepos() {

    E = new PVector(mouseX, mouseY);

    testintersect( La1, La2, E);
    testintersect( La2, Lb1, E);
    testintersect( Lb1, Lb2, E);
    testintersect( Lb2, La1, E);

    if (binary == 2 || binary == 4 ) {
      mouseinside = true;
    } else {
      // mouseinside = false; // check this ?????????????????
    }
  }

  void getEpos() {
    if (mousePressed&&mouseinside) {
      println("Here 1"); 
      beginShape(TRIANGLE);
      vertex(La1.x, La1.y);
      vertex(La2.x, La2.y);
      vertex(E.x, E.y);
      endShape(CLOSE);
    }
  }

  void testintersect(PVector L1, PVector L2, PVector pos) {
    float x1 = L1.x;
    float y1 = L1.y;
    float x2 = L2.x;
    float y2 = L2.y;

    float x3 = pos.x;
    float y3 = pos.y;
    float x4 = 0;
    float y4 = 0;

    float den = (x1-x2) * (y3-y4) - (y1-y2) * (x3-x4);
    if (den == 0) {
      return;
    }
    float t = ((x1-x3) * (y3-y4) - (y1-y3) * (x3-x4)) / den;
    float u = - ((x1-x2) * (y1-y3) - (y1-y2) * (x1-x3)) / den;
    if (t > 0 && t < 1 && u > 0) {
      binary +=1;
    }
  }
}//class
//

```

---

<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:** [May 17, 2021, 3:01pm UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/4 "2021-05-17T15:01:24Z")

</div>

Hello,

Some resources that may help now or in future:

- [https://forum.processing.org/two/discussion/8093/frequently-asked-questions](https://forum.processing.org/two/discussion/8093/frequently-asked-questions) (See Exceptions)
- [Home · processing/processing Wiki · GitHub](https://github.com/processing/processing/wiki) (See Common Errors)

`:)`

---

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [May 18, 2021, 5:31am UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/5 "2021-05-18T05:31:24Z")

</div>

i just want to make a function to check if two lines itersect . it dosent have to be La1 .

---

<div class="post-metadata">

**Author:** ![zang](https://avatars.discourse-cdn.com/v4/letter/z/bc8723/32.png) [@zang](https://discourse.processing.org/u/zang)\
**Post date:** [May 19, 2021, 11:52am UTC](https://discourse.processing.org/t/i-dont-know-why-it-keep-saying-nullpointerexception/30134/6 "2021-05-19T11:52:00Z")

</div>

thanks for give me the link . i will read it seriously. 😊\
