Can't populate a 3D array
in
Programming Questions
•
2 years ago
Hi, I have a large text file. Each line looks something like this:
audio3*Er-zählt schon, er-zählt schon!*8*6
I need to create a three dimensional array for this section of each line: (Er-zählt schon, er-zählt schon!).
Each syllable of the text needs to be assigned a x and y co-ordinate for screen placement.
So I create 2 arrays like this:
String[] sentences; //for textfile
int[][][] words; // [sentence] [syllable] [x, y]
void setup(){
sentences = loadStrings("rig.txt"); //load the textfile into array
createWordsArray(); //populate the words array
}
void draw(){
}
void createWordsArray(){
for (int i=0; i<sentences.length; i++){ //for each line
String[] sentenceElements = split(sentences[i],"*"); //split line
String sentencetext = sentenceElements[1]; //get sentence
sentencetext = sentencetext.replace("-","- "); //add spaces
String[] wordsInSentence = split(sentencetext," ");//split to syllables
for (int j=0; j<wordsInSentence.length; j++){ //for each syllable
words[i][j][0] = 0; //populate words array
words[i][j][1] = 0;
}
}
}
when i run it I get a:
java.lang.NullPointerException
at sketch_sep20b.createWordsArray(sketch_sep20b.java:40)
at this point:
words[i][j][0] = 0;
What am i doing wrong? Is it not possible to populate an array like this? Am I missing something really obvious?
Any help much appreciated!
1