Hi all! Just started with making a game in processing, connected to Arduino where I am using a joystick. Super exciting, however I am a bit stuck because I keep getting the following error message:
NullPointerException
Could not run the sketch (Target VM failed to initialize).
I have tested with easier examples but I don’t understand what this error exactly means. Does it have something to do with the Array?
Here is the code:
/*
DATE: 23_10_2022
CREATIVE CHALLENGE 2: EGBERT THE FISH GAME_version_3
AUTHOR: TAISSIA VISSER
REFERENCES:
https://www.youtube.com/watch?v=jUmjbFsA2zw&ab_channel=Crazy-Logic
*/
// Importing the serial library.
import processing.serial.*;
// Declare serial communication port
Serial myPort;
String inString;
String[] data; // Array of data received from the serial port
// Declare game characters
PImage Campus;
PImage Egbert;
PImage Bottle;
PImage Corn;
PImage Bread;
void setup() {
size (1920, 1081);
String myPortName = Serial.list()[1];
myPort = new Serial(this, myPortName, 9600);
myPort.bufferUntil('\n');
//Campus = loadImage("Egbertbackground.jpg");
//Egbert = loadImage("Egbert.png");
//Bottle = loadImage("plastic.png");
//Corn = loadImage("corn (1).png");
//Bread = loadImage("bread.png");
}
void draw() {
int xPos = int(data[0])/2;
int yPos = int(data[1])/2;
int Pressed = int(data[2]);
//background(Campus);
image(Egbert, xPos, yPos);
//image(Bottle, 100, 100);
//image(Corn, 300, 300);
//image(Bread, 400, 200);
}
// will get called every time data comes in
// storing the data string here
void serialEvent(Serial myPort) {
String inString = myPort.readStringUntil('\n');
if (inString != null)
// removing the whitespace
inString = trim(inString);
// Splitting the string at the commas and
// seperating the variables out into an array
data = split(inString, ",");
}
I can also provide you with the arduino code/ files I have created as a background etc. but I am not sure if that is needed.
Hope someone knows what I have done wrong!
PS: I am making a game about a fish named Egbert who lives in the pond at my University campus
Thanks