우리는 벡터에서 작업중인 내 comp 182 클래스의 프로젝트를 가지고 있지만 "정렬 된 벡터"를 만드는 데 집착하고 있습니다. 그것을 실행하려고하면 ArrayOutofBounds 오류가 발생합니다.
(이하 "howMany"변수가이 "addWord를 사용하여 어레이"theWords "
하고 코드가 10 개 개의 단어 입력 파일을 판독하여 다른 클래스에서 실행되고있는 현의 크기에 대한 카운트이며 "메서드를 사용하여 파일의 단어를"theWords "배열에 추가합니다.
여기에 내가 가지고있는 코드가 있습니다 :
[btw"compareTo "메서드 만 사용할 수 없습니다]Java - ordering/alphabetizing 문자열 배열
public void addWord(String newWord) {
//adds in words
if (howMany < theWords.length) {
theWords[howMany]= newWord;
howMany++;
}
else {
String t [] = new String[capacity+10];
for (int i=0; i <capacity; i++){
t[i] = theWords[i];
}
theWords = t;
theWords[howMany] = newWord;
howMany++;
}
//ordering words
for(int g = howMany - 1, z = howMany ; g < howMany; g--, z--) {
if(newWord.compareTo(theWords[g]) < 0) {
theWords[g] = theWords[z];
theWords[g] = newWord;
}
else
newWord = theWords[z];
}
howMany++;
}
도움을 주시면 감사하겠습니다.
어떤 라인은 예외를 가져오고 staccktrace을 게시하시기 바랍니다 있습니다 – PermGenError