Results 1 to 3 of 3
  1. #1
    nicholil is offline Member
    Join Date
    Nov 2010
    Rep Power

    Default the compile time error is below

    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0

    Program print the runner and print his/her name and time acheived

    Please enter the time and mins of person to find:
    at londondm2.Main.main(
    Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)
    I cannot find what am doing wrong in line 34. my code is below

    Java Code:
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
    package londondm2;
    import java.util.*;
     * @author NicholiL
    public class Main {
         * @param args the command line arguments
        public static void main(String[] args) {
            String[] names = {"Elena", "Demetris", "Katarina", "Phil", "Matteo", "Alexis", "Emmauel", "Amir", "Daniel", "Neda"};
            int[] timesMin = {341, 273, 334, 445, 402, 388, 273, 334, 399, 343};
            int[] timesSec = {25, 30, 37, 44, 56, 5, 12, 51, 14, 27};
            System.out.print("Program print the runner and print his/her name and time achieved");
            System.out.println("Please enter the time and mins of person to find: ");
            String mins_str = args[0];
            int minutes = Integer.parseInt(mins_str);
            String sec_str = args[0];
            int secs = Integer.parseInt(sec_str);
            int IndexOfMins;
            int IndexOfsecs = 0;
            int IndexOfPerson;
            boolean isValidMins = false;
            boolean isValidSecs = false;
            //search the mins array to check if the input mins is included
            //If includede find the position
            //Array startts for 0,1,2,....
            for (int i = 0; i < timesMin.length; i++) {
                if (minutes == timesMin[i]) {
                    IndexOfMins = i;
                    isValidMins = true;
                isValidMins = false;
            //check if the mins is found in the mins array
            //i.e isvalid = true
            //if so then search the secs
            if (isValidMins) {
                for (int i = 0; i < timesSec.length; i++) {
                    if (secs == timesSec[i]) {
                        IndexOfsecs = i;
                        isValidSecs = true;
                    isValidSecs = false;
                System.out.println("The name could not be found for the mins and secs you provided\n");
            //check if the secs is found in the secs array
            //if so then we proceed to find the name
            if (isValidSecs) { 
                //We find the name in the array
                //First we need to check to make sure the IndexOfsec and IndexOfMins
                //should be the same . Meaning they are on the same position in the table
                //so we can then reference the name attribute to them
                System.out.print("The name is: " + names[IndexOfsecs]);
            } else {
                System.out.println("The name could not be found for the mins and secs you provided\n");
    Last edited by Eranga; 11-07-2010 at 02:50 AM. Reason: code tags added

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power


    Quote Originally Posted by nicholil View Post
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
    That's not a compile time error, i.e. the error happened when you tried to run the program so it's a runtime error. Did you supply at least one command line argument to the program because it tries to read one, i.e. did you run your program as follows?

    Java Code:
    java Main <an argument goes here>
    kind regards,


  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    I've added code tags into your code segment. Please use code tags next time when you are posting code segment in the forum. Unformatted codes are really hard to read. If you don't know how to do that, please check in my forum signature. You can find the link to proper explanation.

    Regarding your question, do you know what's doing in,

    Java Code:
    String mins_str = args[0];

Similar Threads

  1. Runtime/Compile Time Exceptions
    By in forum New To Java
    Replies: 1
    Last Post: 10-18-2010, 11:32 AM
  2. High Compile Time
    By Mojito_gr in forum Advanced Java
    Replies: 7
    Last Post: 08-02-2010, 04:47 AM
  3. Replies: 0
    Last Post: 07-09-2009, 11:11 AM
  4. Java 1.5 compile time error
    By ank_k in forum New To Java
    Replies: 4
    Last Post: 11-13-2008, 12:12 PM
  5. Help with Compile time errors
    By bri1547 in forum New To Java
    Replies: 2
    Last Post: 08-24-2008, 11:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts