We are about to switch to a new forum software. Until then we have removed the registration on this forum.
T got found this example....
int io=0;
int counter=0;
PFont myFont;
String[] test;
String[] test2;
void setup(){
size(512, 512);
smooth();
background(0);
myFont = createFont("xkcd", 64);
textFont(myFont);
textAlign(CENTER);
io = 0;
counter=0;
}
void draw(){
background(0);
text(counter, height/2, width/2);
text("Test2 "+test2[0], 50, 50); /// NullPointerException
println(test2[1]);
counter++;
}
void keyPressed() {
if (key == '1') {
openData();
}
}
void openData() {
println("open data...");
// stop the draw() function
noLoop();
selectInput("Select a file...", "myFile");
println("...function end.");
}
void Textsichern (String[] _val) { /// My modifying.
test2 = _val;
text("Test2 "+test2[0], 50, 50);
println(test2[1]);
}
void myFile(File selection) {
io=1;
if (selection == null) {
println("No file selected.");
} else {
println("File selected: " + selection.getAbsolutePath());
counter=0;
Textsichern(loadStrings(selection.getAbsolutePath())); /// My modifying.
}
// restart the draw() function
loop();
io=0;
}
...and modifying them. Error at line 22
Gruß Willi
Answers
Nothing is assigned to
test2[0]
in the first iteration ofdraw()
, which is why you get a null pointer exception. You migh try assigning it an empty string insetup()
:Hey, thanks for the quick response. It´s so simple, but i didn't see it. I got try it with "try - catch".
The code is running, but with exceptions. Yours is much better.
Happy Easter.
Happy Easter!
if(text...!=null) {.....
Or you have a state/ stage system and wait until the loading succeeded