troubles with arrays, index out of bounds exception : <p>So i've been at this problem for awhile, It's a piece of code that is suppose to display the data that has already been collected and sorted from the user. First ill post the code than ill post the error.</p>

<pre><code>import java.util.Scanner;
import java.util.*;
public class project3
{
   private static double[] payrate;
   private static String[] names;


   public static void SortData(double payrate[])
    {
         int first;
         int temp;
         int i;
         int j;
         for(i = payrate.length - 1; i &gt; 0; i--)
         {
            first = 0;
            for(j = 1; j&lt;=i;j++)
            {
               if(payrate[j]&lt;payrate[first])
               first = j;
            }
            temp = (int)payrate[first];
            payrate[first] = payrate[i];
            payrate[i] = temp; 
         } 
    }

   public static void GetData()
   {

    Scanner input = new Scanner(System.in);
     System.out.println("How many names do you want to enter?");
                String strNum = input.nextLine();
                int num = Integer.parseInt(strNum);
                int array[] = new int[num];
                for (int i = 0  ; i &lt; array.length ; i++ ) 
                    {
                        names = new String[num];


                        System.out.println("enter employee's name: ");

                        names[i] = input.nextLine(); 
                        //while(names[i].length &lt; 2)
                        //{
                           //System.out.println("enter valid employee's name: ");

                        //names[i] = input.nextLine(); 
                        //} 

                    }
                for(int j = 0; j &lt; array.length;j++)
                    {
                        payrate = new double[num];
                        System.out.println("enter employee's payrate: ");
                        payrate[j] = input.nextDouble();
                        while(payrate[j] &gt; 100 || payrate[j] &lt; 0)
                        {
                           System.out.println("enter valid employee's payrate: ");
                           payrate[j] = input.nextDouble();
                        }


                     }


   }
        public static void DisplayData(double payrate[], String names[])
    {
         int locationsum = 0;
         for (int l=1; l&lt;=names.length; l++) 
         {

            locationsum = 0;

           locationsum+=payrate[l];
           }

           for(int i=0;i&lt;names.length;i++)
           {
              System.out.print(names[i]);

           System.out.printf("%6d\n", locationsum);

           } 

    }

    public static void main(String[] args)
   {
      GetData();
      SortData(payrate);
      DisplayData(payrate,names);

   }




}
</code></pre>

<p>I can't figure out a way to print out all of the stuff from the arrays, and with this way it keeps giving me this. The error I'm getting is : </p>

<pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
    at project3.DisplayData(project3.java:77)
    at project3.main(project3.java:94)
</code></pre>
