Syntax help with 2D array

Can you paste your code which is throwing the nullpointer exception? It may be that you’ve got your chord/notes order reversed in the array.

Just putting all the discussed parts together works fine for me.

The @GoToLoop approach:

static final byte[][] chordBank2 = {
  { 40, 45, 50, 55, 59, 64 }, // open strings 0
  { 40, 47, 52, 56, 59, 64 }, // E major      1
  { 41, 48, 53, 57, 60, 65 }, // F major      2                   
  { 43, 47, 50, 55, 59, 67 }, // G major      3
  { 33, 45, 52, 57, 61, 64 }, // A major      4
  { 35, 47, 54, 59, 63, 66 }, // B major      5
  { 36, 48, 52, 55, 60, 64 }, // C major      6
  { 38, 38, 50, 57, 62, 66 }  // D major      7
};

void setup() {
}

void draw() {
  printChord(2); // prints chord 2 
}

void printChord(int chord){ // print a chord
    for(int i=0; i<6; i++){
    print(" ",chordBank2[chord][i]);
  }
  println();
}

My approach:

byte[][] chordBank2 = new byte[8][6];

void setup() {  
  chordBank2[0] = new byte[] {40, 45, 50, 55, 59, 64}; // open strings
  chordBank2[1] = new byte[] {40, 47, 52, 56, 59, 64}; // E major
  chordBank2[2] = new byte[] {41, 48, 53, 57, 60, 65}; // F major
  chordBank2[3] = new byte[] {43, 47, 50, 55, 59, 67}; // G major
  chordBank2[4] = new byte[] {33, 45, 52, 57, 61, 64}; // A major
  chordBank2[5] = new byte[] {35, 47, 54, 59, 63, 66}; // B major
  chordBank2[6] = new byte[] {36, 48, 52, 55, 60, 64}; // C major
  chordBank2[7] = new byte[] {38, 50, 57, 62, 66, 69}; // D major 
}

void draw() {
  printChord(2); // prints chord 2 
}

void printChord(int chord){ // print a chord
    for(int i=0; i<6; i++){
    print(" ",chordBank2[chord][i]);
  }
  println();
}