Results 1 to 3 of 3
Thread: the compile time error is below
- 11-06-2010, 09:35 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
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(Main.java:34)
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.*; import java.io.*; /** * * @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.println("\n"); System.out.print("Program print the runner and print his/her name and time achieved"); System.out.println("\n"); System.out.println("\n"); 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; break; } 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; break; } 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) { //Next //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 01:50 AM. Reason: code tags added
- 11-06-2010, 10:28 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,420
- Blog Entries
- 7
- Rep Power
- 17
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?
kind regards,Java Code:java Main <an argument goes here>
Jos
- 11-07-2010, 01:52 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
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,
line?Java Code:String mins_str = args[0];
Similar Threads
-
Runtime/Compile Time Exceptions
By suresh.sa in forum New To JavaReplies: 1Last Post: 10-18-2010, 11:32 AM -
High Compile Time
By Mojito_gr in forum Advanced JavaReplies: 7Last Post: 08-02-2010, 04:47 AM -
Compile time Annotation Processing - Maven build problem
By Milesy in forum Advanced JavaReplies: 0Last Post: 07-09-2009, 11:11 AM -
Java 1.5 compile time error
By ank_k in forum New To JavaReplies: 4Last Post: 11-13-2008, 11:12 AM -
Help with Compile time errors
By bri1547 in forum New To JavaReplies: 2Last Post: 08-24-2008, 11:22 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks