I’m braking down a bigger code in to small parts.
Now i’m stuck with what I guess is a basic things.
I would like to simply display words I have in a text file .txt.
I written a code but i get the error “null pointer exception”, I can’t understand how to populate a string.
Can some one explain me please, what I am doing wrong?
Thanks
PS: i’ve already saw tones of video/documentation and so on… but i’m still stuck…
PFont font;
String [] lines;
void setup() {
size(900, 500);
background(0);
font = loadFont("MaisonNeue-Demi-96.vlw");
String[] lines = loadStrings("myText.txt");
printArray(lines); // I visualize the content of the file in the console
}
void draw() {
for (int i = 0; i < lines.length; i++) { // error, I guess lines is empty --> how can i populate this string?
textFont(font);
fill(255);
text(lines[i], 300, 250);
}
}
Hey, thanks for the answer.
I load a screenshot to confirm that i see the lines.
I set the background in the setup function, is that not enough?
I was expecting that the words would have been displayed all in the same position but I was thinking to find a solution after I could manage to display them
The reason is that you are creating a new variable by using String[] in your setup. So your variable is not global anymore. Just delete that and it should be fine.
Hey, thank you a lot for your help, it is very kind from you!
I make a test with the function make_wordcloud you suggested me including the PGraphics. Then more I have the feeling that i’m getting closer to my final goal then more bigger problems that i could not think about comes out!
Now i display the words and every time a new word comes in I redraw and it display it.
a: the words already been displayed they change position with the new draw
b: words are sometimes one over the other
c: the words are random size
Puff I still have to go trough lots of problems… I’ll keep working on it and try to break down the problems in to smaller ones… I’ll keep you update