NullPointerException Issue (Help!)
in
Programming Questions
•
7 months ago
I've done the coding, however I'm getting a NullPointerException error. All I want is for whenever the user clicks the mouse, it plays a sound on a loop, and when the mouse is released the sound stops. What am I doing wrong?
Much appreciated.
Much appreciated.
- first circle_;
second_[] smallcircle = new second_[4000];
import ddf.minim.* ;
Minim minim;
AudioPlayer au_player1 ;
// Button Features
boolean knobHighlight1 = false;
boolean knobHighlight2 = false;
float knob1, knobOne, knob2, knobTwo;
int xKnob1;
int yKnob1;
int yKnob2;
int knobMass;
PImage bg;
void setup() {
size(640,480);
minim = new Minim(this);
au_player1 = minim.loadFile("bubbles.wav");
textSize(30);
text("Fill My World With Colour",50,50);
textAlign(CENTER,CENTER);
circle_ =new first ();
for (int s = 0; s <100; s++) {
circle_ = new first();
smallcircle[s]=new second_();
}
knob1 = color(350);
knobOne = color(230);
knob2 = color(350);
knobTwo = color(230);
xKnob1=470;
yKnob1=10;
yKnob2=40;
knobMass=10;
}
void draw() {
update(mouseX, mouseY);
// Knobs Are Lit With Colour When Highlighted By Mouse
if (knobHighlight1) {
fill(knob1);
knob1pressed(); // Function For Chosen Knob
}
else {
fill(knobTwo);
}
ellipse (xKnob1, yKnob1, knobMass, knobMass);
if (knobHighlight2) {
fill(knob2);
knob2pressed();
}
else {
fill(knobTwo);
}
ellipse (xKnob1, yKnob2, knobMass, knobMass);
}
// Boolean To Cause Action Once Mouse Is Pressed
void update(int x, int y) {
if ( knobHighlight1(xKnob1, yKnob1, knobMass)) {
knobHighlight1 = true;
knobHighlight2 = false;
}
else if ( knobHighlight2(xKnob1, yKnob2, knobMass) ) {
knobHighlight1 = false;
knobHighlight2 = true;
}
}
// Position of the Knobs
boolean knobHighlight1(int x, int y, int diameter) {
float xRange = x - mouseX;
float yRange = y - mouseY;
if (sqrt(sq(xRange) + sq(yRange)) < 15 ) {
return true;
}
else {
return false;
}
}
boolean knobHighlight2(int x, int y, int diameter) {
float xRange = x - mouseX;
float yRange = y - mouseY;
if (sqrt(sq(xRange) + sq(yRange)) < 15 ) {
return true;
}
else {
return false;
}
}
void knob1pressed() {
if (mousePressed==true) {
fill(0);
circle_.draw_();
noStroke();
fill(random(0, 255));
}
}
void knob2pressed() {
if (mousePressed==true) {
for (int s = 0; s < 50; s++) {
fill(0);
smallcircle[s].draw_();
smallcircle[s].move();
}
}
}
void mousePressed(){
au_player1.play();
au_player1.loop();
}
void mouseReleased(){
au_player1.close();
minim.stop();
}
1