Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.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
java StringIndexOutOfBoundsException:字符串索引超出范围:0_Java_Arrays_String_Indexing - Fatal编程技术网

java StringIndexOutOfBoundsException:字符串索引超出范围:0

java StringIndexOutOfBoundsException:字符串索引超出范围:0,java,arrays,string,indexing,Java,Arrays,String,Indexing,这是一个非常简单的函数。我不知道为什么它为函数source.charAt(I)提供了StringIndexOutOfBoundsException。我已检查“I”的值是否不超过字符串的长度,该长度始终为9 public static String getClockResetString(String source, String target, Hashtable order) { String temp = "",name; for(int i = 0; i < sou

这是一个非常简单的函数。我不知道为什么它为函数source.charAt(I)提供了StringIndexOutOfBoundsException。我已检查“I”的值是否不超过字符串的长度,该长度始终为9

public static String getClockResetString(String source, String target, Hashtable order)
{
    String temp = "",name;

    for(int i = 0; i < source.length(); i++){
        name = (String)order.get(""+i);

                if(source.charAt(i) != target.charAt(i))
                {
                    if((int)source.charAt(i) < (int)target.charAt(i)){
                        temp = "h" + name + "=" + "dp" + name + "0" + " do " + "{h" + name + "'=0, k'=k+1} ";
                    }
                    else{
                        temp = "h" + name + "=" + "dn" + name + "1" + " do " + "{h" + name + "'=0, k'=k+1} ";
                    }
                }

    }

    return temp;
}
公共静态字符串getClockResetString(字符串源、字符串目标、哈希表顺序)
{
字符串temp=”,名称;
对于(int i=0;i
我打赌你超出了目标的界限,而不是源的界限

if(source.charAt(i) != target.charAt(i))
你需要检查一下

i < target.length()
i
您将向此方法传递哪些参数
source
为空。异常不存在。可能
target
source
短。如果出现异常,您的一个字符串似乎是空字符串。。。还有,为什么要在2015年使用
哈希表
?它已经被淘汰至少10年了…它是一个9位的基因序列。这是我上司的老规矩。源和目标不为空。秩序也在运作。少数几个州出现了例外情况。