NullPointerException with multidimensional arrays
in
Programming Questions
•
2 months ago
I am sure that I am doing something very basic wrong here, but I cannot identify what it is because of my lack of experience using multidimensional arrays. I have read this:
CommonErrors - Processing and I assume it is a problem with me having not properly allocated space for the array(s), even though the error comes up when I try to do that.
- PFont font;
- String[] settings;
- String[] sdata;
- String[] rawdata;
- String[][] tkdata;
- int i;
- int j = 0;
- void setup() {
- size(1, 1);
- frame.setResizable(true);
- sdata = loadStrings(dataPath("../../settings.txt"));
- settings = new String [sdata.length/2];
- println(settings.length);
- for (i = 0; i < sdata.length; i++) {
- if (i%2 != 0) {
- settings[j] = sdata[i];
- println(sdata[i]);
- j++;
- }
- }
- size(int(settings[0]), int(settings[1]));
- for (i = int(settings[10]); i <= int(settings[11]); i++) {
- loadTrikinetics(i);
- }
- }
- void draw() {
- background(color(int(settings[6])));
- stroke(color(int(settings[8])));
- textAlign(CENTER, CENTER);
- font = createFont("CourierNewPSMT", 16, true);
- textFont(font, 16);
- text("test", width/2, height/2);
- }
- void loadTrikinetics(int monitornum) {
- rawdata = loadStrings(dataPath(settings[9]+"Monitor"+monitornum+".txt"));
- tkdata = new String[rawdata.length][42];
- for (i = 0; i < rawdata.length; i++) {
- tkdata[i] = split(rawdata[i], " ");
- println(rawdata[i]);
- }
- for (i = 0; i < tkdata[5].length; i++) {
- println(tkdata[5][i]);
- }
- }
I have the whole (unfinished) code above, with the area of interest highlighted in yellow and the line that is highlighted for the NullPointerException error highlighted in green. I would be surprised if this was not a simple fix, but I cannot seem to figure out what it is. Thanks!
~J
1