parent.random() gives me a NullPointerException
in
Programming Questions
•
2 years ago
Hi guys. For some reason every method for parent but random() seems to work for me. It's weird because I've tried other projects that also called parent.random() and they work fine. I use Eclipse to program.
Here's the error message:
Exception in thread "Animation Thread" java.lang.NullPointerException
at Video.<init>(Video.java:22)
at sketch_jun1.setup(sketch_jun1.java:13)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
And here is the class where the error is found.
Here's the error message:
Exception in thread "Animation Thread" java.lang.NullPointerException
at Video.<init>(Video.java:22)
at sketch_jun1.setup(sketch_jun1.java:13)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
And here is the class where the error is found.
- import processing.core.PApplet;
- import processing.core.PImage;
- public class Video {
- int w, h, x, y, littleX, littleY, bigX, bigY, savedXSpeed, savedYSpeed, circleW, circleH;
- float xSpeed, ySpeed;
- PImage myImage;
- PApplet parent;
- boolean tooBig = false;
- public Video(PApplet p, int xx, int yy, PImage img) {
- x = xx;
- littleX = xx;
- y = yy;
- littleY = yy;
- w = 120;
- h = 90;
- circleW = w + 20;
- circleH = h + 20;
- bigX = x + w + 6;
- bigY = y + h + 6;
- xSpeed = parent.random(1);
- ySpeed = parent.random(-1);
- parent = p;
- myImage = img;
- }
- public void display() {
- parent.noStroke();
- parent.fill(250, 0, 0, 50);
- parent.ellipse(x+60, y+45, circleW, circleH);
- parent.image(myImage,x,y);
- }
- public void move() {
- x += xSpeed;
- y += ySpeed;
- if (x + w > bigX || x < littleX)
- xSpeed *= -1;
- if (y + h> bigY || y < littleY)
- ySpeed *= -1;
- }
- public void increaseSize(){
- circleW = circleW + 4;
- circleH = circleH + 4;
- }
- public void decreaseSize(){
- circleW--;
- circleH--;
- }
1