这部分程序给我带来了麻烦。该程序正确接收该文件。没有charAt方法,程序运行完美。我不确定问题是什么。显然,这不是整个程序,只是给我一个错误的部分。
错误:
java.lang.StringIndexOutOfBoundsException:字符串索引超出范围: 0在java.lang.String.charAt(未知来源)at GenSeq.main(GenSeq.java:111)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(未知来源)at sun.reflect.DelegatingMethodAccessorImpl.invoke(未知来源)at java.lang.reflect.Method.invoke(未知来源)at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:272)
程序:
do{
line = inputStream.nextLine();
line = line.trim();
if (line.charAt(0) == '>'){
//Checking to see if it's an information line
info = info + line;
count++;
//Used to count the number of entries
}
else{
seq = seq + line;
//Concatenating the sequence together
}
while (inputStream.hasNextLine());
inputStream.close();
编辑:我们正在处理DNA和RNA序列,所以它可以开始的唯一字母是A,T,C,G或U.为了处理空白行,我现在尝试了。仍然得到错误。
do{
line = inputStream.nextLine();
char first = line.charAt(0);
if (first == '>'){
//Checking to see if it's an information line
info = info + line;
count++;
//Used to count the number of entries
}
if (first == 'A' || first == 'T' || first == 'G' || first == 'C' || first == 'U'){
seq = seq + line;
}
}
while (inputStream.hasNextLine());
inputStream.close();
答案 0 :(得分:2)
可能的解决方案是用line.charAt(0) == '>'
替换line.startsWith (">")
至少可以解除数组的问题,你可以从那里完成调试。