D
Deleted User
Guest
OP
Hi all, hoping someone can help a java noob here.
Learning Java in my college course, but I've come across a little snag.
I have to create a little app to draw some orbs on a display, but I always get "NullPointerException" error when I enter a value.
I understand that it's because I'm not initialising my target integer, but I cannot for the love of me understand WHY I'm not initialising it.
Anyone wanna point out to me what I'm doing and why?
Main
Action class
Learning Java in my college course, but I've come across a little snag.
I have to create a little app to draw some orbs on a display, but I always get "NullPointerException" error when I enter a value.
I understand that it's because I'm not initialising my target integer, but I cannot for the love of me understand WHY I'm not initialising it.
Anyone wanna point out to me what I'm doing and why?
Main
import javax.swing.*;
Action ac;
void setup(){
size(1920,1080);
noStroke();
frameRate(144);
fill(255); //background white (for now)
rect(0,0,1920,1080); //Right screen edge block
fill(0,120,200); //Edge data block colors, light blue
rect(0,0,550,1080); //Left data block
rect(1370,0,1920,1080); //Right data block
textSize(60);
text("BlitzBall v0.1", 95, 60);
int flotsome = Integer.parseInt(JOptionPane.showInputDialog("How many balls to spawn ", "2"));
ac.setAmount(flotsome);
}
void draw(){
ac.display();
print(ac.amount);
}
Action ac;
void setup(){
size(1920,1080);
noStroke();
frameRate(144);
fill(255); //background white (for now)
rect(0,0,1920,1080); //Right screen edge block
fill(0,120,200); //Edge data block colors, light blue
rect(0,0,550,1080); //Left data block
rect(1370,0,1920,1080); //Right data block
textSize(60);
text("BlitzBall v0.1", 95, 60);
int flotsome = Integer.parseInt(JOptionPane.showInputDialog("How many balls to spawn ", "2"));
ac.setAmount(flotsome);
}
void draw(){
ac.display();
print(ac.amount);
}
Action class
class Action{
private int amount;
int xLoc[];
int yLoc[];
//============
//Constructors
//============
Action(){
}
Action(int amount){
this.amount = amount;
print("Constructor check " + amount);
}
Action(int xLoc, int yLoc){
//Dummy for now
}
//=======
//Methods
//=======
void display(){
if(amount == 1){
ellipse(900,540,50,50);
}
else if(amount == 2){
ellipse(800,540,50,50);
ellipse(900,540,50,50);
}
else if(amount == 3){
ellipse(800,540,50,50);
ellipse(900,540,50,50);
ellipse(1000,540,50,50);
}
else{
}
}
//=======
//Setters
//=======
public void setAmount(int amount){
if((amount > 0) && (amount <= 3)){
this.amount = amount;
print("Setter Check " +amount);
}
}
/*
public void setLocs(int passX, int passY){
if((passX >= 0) && (passX <= 1920)){
//this.xLoc = passX;
}
else{
}
if((passY >= 0) && (passY <= 1080)){
//this.yLoc = passY;
}
else{
}
}
*/
//=======
//Getters
//=======
}
private int amount;
int xLoc[];
int yLoc[];
//============
//Constructors
//============
Action(){
}
Action(int amount){
this.amount = amount;
print("Constructor check " + amount);
}
Action(int xLoc, int yLoc){
//Dummy for now
}
//=======
//Methods
//=======
void display(){
if(amount == 1){
ellipse(900,540,50,50);
}
else if(amount == 2){
ellipse(800,540,50,50);
ellipse(900,540,50,50);
}
else if(amount == 3){
ellipse(800,540,50,50);
ellipse(900,540,50,50);
ellipse(1000,540,50,50);
}
else{
}
}
//=======
//Setters
//=======
public void setAmount(int amount){
if((amount > 0) && (amount <= 3)){
this.amount = amount;
print("Setter Check " +amount);
}
}
/*
public void setLocs(int passX, int passY){
if((passX >= 0) && (passX <= 1920)){
//this.xLoc = passX;
}
else{
}
if((passY >= 0) && (passY <= 1080)){
//this.yLoc = passY;
}
else{
}
}
*/
//=======
//Getters
//=======
}
Last edited by ,