Click here to Skip to main content
15,886,795 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Here are my two files..
Java
import java.time.*;
/**
 *
 * @author 
 */
public class Clock  {
	public static void main(String[] args){}
    private LocalTime startTime;
    private LocalTime stopTime;

    public Clock(){
        startTime=LocalTime.now();

    }

    /**
     * Set the start time 
     * @param time: start time
     **/
    public void start(LocalTime time){
        startTime= time;
    }
    
    
    /**
     *Set the Stop time 
     * @param time: stop time
     **/
    public void stop(LocalTime time){
        stopTime=time;
    }
    
    /**
     * This method will return total elapsed time
     **/
    public int getElapsedTime(){
        return (stopTime.toSecondOfDay() -startTime.toSecondOfDay());
    }//End Main
    
}//End Class


Java
import java.time.*;
/**
 *
 * @author 
 */
public class TestClock {
    public static void main (String[] args){
        Clock clock=new Clock();
        clock.start(LocalTime.parse(args[0]));
        clock.stop(LocalTime.parse(args[1]));
        System.out.println("Elapsed time in seconds is: "+clock.getElapsedTime());
    }//End Main
}//End Class

Im getting the following error...

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at TestClock.main(TestClock.java:18)

Not sure where to go due to being new to Java.

Thank you.
Posted
Updated 2-May-15 12:24pm
v2
Comments
Mohibur Rashid 2-May-15 18:59pm    
First of try to debug the program. Array index out of bounds exception happens when you try to access and index that does not exists. do you have args[1]?

1 solution

Can you show how you are calling your Java program from the command line? It looks like you are missing arguments to your Java program.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900