title: Java sorting parallel arrays, help needed (NullPointerException Error)
body: <p>Ok I am trying to finish this program for my into to java class and I am having trouble with this one part. Everything else is working except this. I have 3 arrays, 1 string, 2 type int, all parallel. I have to sort these into alphabetical order by name then by number (using the string array first, then the first int array, sorting is not affected by the third array, it is there to practice parallel in 3 dimensions)</p>
  
  <p>This is the code I have so far.</p>
  
  <pre><code>    public static void sortDatabase(int numRecords, String[] sDeptArr, 
                int[] iCourseNumArr, int[] iEnrollmentArr)
     {
         System.out.println("Sort the database. \n");
         String sTemp = null;
         int iTemp = 0;
         int eTemp = 0;
         for(int i=0; i&lt;numRecords; i++)
         {
             int iPosMin = i;
             for(int j=i+1; j&lt;numRecords; j++)
             {
                 String a = sDeptArr[j];
                 String b = sDeptArr[iPosMin];
                 if(a.compareTo(b) != 0)
                     iPosMin = j;
                 else if(!sDeptArr[j].equals(sDeptArr[iPosMin]) &amp;&amp; iCourseNumArr[j] &lt; iCourseNumArr[iPosMin])
                     iPosMin = j;
             }
             sDeptArr[i] = sTemp;
             sDeptArr[i] = sDeptArr[iPosMin];
             sDeptArr[iPosMin] = sTemp;
             iCourseNumArr[i] = iTemp;
             iCourseNumArr[i] = iCourseNumArr[iPosMin];
             iCourseNumArr[iPosMin] = iTemp;
             iEnrollmentArr[i] = eTemp;
             iEnrollmentArr[i] = iEnrollmentArr[iPosMin];
             iEnrollmentArr[iPosMin] = eTemp;
         }
     }
  </code></pre>
  
  <p>It has to be done in java. I am getting an error in the 15th line consisting of </p>
  
  <pre><code>if(a.compareTo(b) != 0)
  </code></pre>
  
  <p>and I am getting a NullPointerException.</p>
  
  <p>Basically I am sorting fake class names and course numbers while keeping the number of people enrolled parallel with its corresponding index to the course name and number.</p>