请帮助我解决我在迷你时钟程序中遇到的这个错误 [英] Please help me out with this error I am getting in my mini clock program

查看:77
本文介绍了请帮助我解决我在迷你时钟程序中遇到的这个错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的两个文件..

Here are my two files..

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







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



我收到以下错误...



线程main中的异常java.lang.ArrayIndexOutOfBoundsException:0
$ C $ b在TestClock.main(TestClock.java:18)



由于不熟悉Java,不确定去哪里。



谢谢。


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.

推荐答案

您能说明如何从命令行调用Java程序吗?看起来您缺少Java程序的参数。
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.


这篇关于请帮助我解决我在迷你时钟程序中遇到的这个错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆