Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
I';我在java项目中获得了StringOutOfBoundsException else if(args.length==5) { 字符串firstyear=args[3]; 字符串secondyear=args[4]; 字符串datayear=temp[0]; DateFormat df=新的简化格式(“dd/MM/yyyy”); 第一个日期=df.parse(第一年); 第二个日期=df.parse(第二年); 日期数据=df.parse(数据年); 工作日=转换日期到工作日(温度); 如果(工作日==天| |天==0); { if(temp[8].contentEquals(drawtype) ||drawtype.contentEquals(“A”)){ 如果((数据等于(第一))| |(数据等于(第二)) ||((第一次之后的数据)和&(第二次之前的数据){ 如果(选项==1 | |选项==2){ 对于(int count=0;count_Java_String_Runtime Error_Indexoutofboundsexception - Fatal编程技术网

I';我在java项目中获得了StringOutOfBoundsException else if(args.length==5) { 字符串firstyear=args[3]; 字符串secondyear=args[4]; 字符串datayear=temp[0]; DateFormat df=新的简化格式(“dd/MM/yyyy”); 第一个日期=df.parse(第一年); 第二个日期=df.parse(第二年); 日期数据=df.parse(数据年); 工作日=转换日期到工作日(温度); 如果(工作日==天| |天==0); { if(temp[8].contentEquals(drawtype) ||drawtype.contentEquals(“A”)){ 如果((数据等于(第一))| |(数据等于(第二)) ||((第一次之后的数据)和&(第二次之前的数据){ 如果(选项==1 | |选项==2){ 对于(int count=0;count

I';我在java项目中获得了StringOutOfBoundsException else if(args.length==5) { 字符串firstyear=args[3]; 字符串secondyear=args[4]; 字符串datayear=temp[0]; DateFormat df=新的简化格式(“dd/MM/yyyy”); 第一个日期=df.parse(第一年); 第二个日期=df.parse(第二年); 日期数据=df.parse(数据年); 工作日=转换日期到工作日(温度); 如果(工作日==天| |天==0); { if(temp[8].contentEquals(drawtype) ||drawtype.contentEquals(“A”)){ 如果((数据等于(第一))| |(数据等于(第二)) ||((第一次之后的数据)和&(第二次之前的数据){ 如果(选项==1 | |选项==2){ 对于(int count=0;count,java,string,runtime-error,indexoutofboundsexception,Java,String,Runtime Error,Indexoutofboundsexception,这是我必须为大学做的一个项目。其目的是分析两个日期之间以及不同抽奖的彩票信息。它给出了以下错误: 线程“main”java.lang.StringIndexOutOfBoundsException中出现异常:字符串索引超出范围:-1 它从命令行中获取两个日期,从文件中读取一行并将其放入名为temp的数组中。程序的其余部分工作正常,但如果进入这一部分,它就会崩溃并产生错误。有人能发现是什么导致了错误吗。我也知道我可以写得更好,但我希望在我专注于编写好代码之前,先让它工作起来 编辑:BonusNum

这是我必须为大学做的一个项目。其目的是分析两个日期之间以及不同抽奖的彩票信息。它给出了以下错误:

线程“main”java.lang.StringIndexOutOfBoundsException中出现异常:字符串索引超出范围:-1

它从命令行中获取两个日期,从文件中读取一行并将其放入名为temp的数组中。程序的其余部分工作正常,但如果进入这一部分,它就会崩溃并产生错误。有人能发现是什么导致了错误吗。我也知道我可以写得更好,但我希望在我专注于编写好代码之前,先让它工作起来

编辑:BonusNumber和JackpotNumber都是45长的整数数组。temp是一个字符串数组,temp[0]是一个日期,例如10/07/1994。jackpot是一个45长的整数数组。 如果(工作日==天| |天==0);这是为了检查从文件中读取的日期是否为用户提供的某一天。 我不知道你所说的堆栈跟踪或使用调试器是什么意思。我对编程是新手


编辑2:我知道这个错误在这个部分,因为它只有在我运行这个部分时才会崩溃。我可以运行代码的其他部分而不会崩溃。在这个错误之后,它只会说每个方法的名称。你提到你是“编程新手”,所以你不知道[是什么意思]通过堆栈跟踪或使用调试器“。那么,您如何知道是这段代码导致了问题?您一定在IDE的控制台中看到了一些东西(假设您正在使用IDE,或者您可能正在从命令行运行它?在任何一种情况下,在您发布的内容后面都应该有很多行文字,如“at java…”。无论如何,如果有,那么这就是您的stacktrace(基本上,是导致出现
StringIndexOutOfBoundsException
的程序执行行)


不管怎样,由于它抛出了一个
StringIndexOutOfBoundsException
,我想说您的
contentEquals(…)
方法调用非常可疑。但是,正如其他人所说,如果没有更多的信息,就不可能说了。

那么哪一行引发了异常?您能否将代码示例简化为一个简短但完整的程序来演示问题。如果您能格式化代码,这也会非常有帮助-很难阅读没有适当的缩进。你能粘贴堆栈跟踪的前10行吗?尝试将其缩小到更具体的代码行。你向我们展示的代码位有许多变量没有在代码的该部分中定义/分配(它们可能在之前,但我们不知道这一点)。使用你的调试器,异常会在哪里抛出?这行代码做什么?
如果(工作日==day | | day==0)
太多未知:
bonusnumbers
temp
jackpot
jackpot numbers
。你希望我们如何帮助你?
else if (args.length == 5)
    {
        String firstyear = args[3];
        String secondyear = args[4];
        String datayear = temp[0];
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date first = df.parse(firstyear);
        Date second = df.parse(secondyear);
        Date datas = df.parse(datayear);
        weekday = convertDateToWeekDay(temp);
        if (weekday == day || day == 0);
        {
            if (temp[8].contentEquals(drawtype)
                    || drawtype.contentEquals("A")) {
                if ((datas.equals(first)) || (datas.equals(second))
                        || ((datas.after(first)) && (datas.before(second)))) {
                    if (choice == 1 || choice == 2) {
                        for (int count = 0; count < jackpot.length; count++) {
                            jackpot[count] = Integer
                                    .parseInt(temp[count + 1]);
                            jackpotnumbers[jackpot[count] - 1]++;
                        }
                    }
                    if (choice == 2) {
                        bonus = Integer.parseInt(temp[7]);
                        if (temp[8].contentEquals(drawtype)
                                || drawtype.contentEquals("A"))
                            bonusnumbers[bonus - 1]++;
                    }
                }
            }
        }
    }

}