배열 예외가 발생합니다. 예외가 발생합니다. 나는 그 배열이 비어 있기 때문에 그것의 내용을 사용하려고 시도하기 전에 그 길이를 체크한다. 그러나 어레이가 null 포인터 예외를 발생시키는 이유 때문에 검사를 수행하지도 않습니다. 왜 그걸 던지는 사람?범위를 벗어나는 배열 및 null 포인터 예외
여기 여기에 코드를
private void createGroupTree(ArrayList<String> groupList) throws JWNLException {
WordNetMeasures wordNet = new WordNetMeasures();
String[] wordResult;
for(int i = 0; i<groupList.size(); i++) {
wordResult = wordNet.getWordNetPath(groupList.get(i));
if(wordResult.length == 0) {
graph.addVertex(groupList.get(i));
} else {
for(int j=0; j<wordResult.length; j++) {
if(j !=wordResult.length-1) {
graph.addEdge(edgeFactory.create(), wordResult[j], wordResult[j+1]);
}
}
}
}
}
있어이 문제의 원인이되는 getWordNetPath 방법에 대한 코드입니다. 목록에있는 일부 단어가 사전에 사용되지 않고 있다는 것을 알고 있습니다. 나는 그 문제를 일으키기 위해 어떻게 처리해야할지 모릅니다.
public String[] getWordNetPath(String word) throws JWNLException {
RiWordnet wordnet = new RiWordnet();
//String wordOne = "dog";
String[] posOfWord = wordnet.getPos(word);
int[]wordIds = wordnet.getSenseIds(word, posOfWord[0]);
String[] wordResults = wordnet.getHypernymTree(wordIds[0]);
return wordResults;
}
[자바 초보자를위한이 디버깅 안내서] (http://keysersblog.wordpress.com/2014/04/21/debugging-java-code-a-beginners-guide/)에 관심이있을 수 있습니다. 사람들이 기본 디버깅을 시작하는 데 도움이되도록 작성했습니다. – keyser
ArrayIndexOutOfBoundsException * 또는 *가 발생하거나 NullPointerException이 발생합니다. 둘 다받을 수는 없습니다. 그것은 당신이 예외를 얻고있는 곳을 우리에게 말하지 않았음에도 도움이되지 않습니다. 또한 코드가 급격하게 들여 쓰기에 도움이되지 않습니다. ( –
둘 다 얻고 있습니다. wordResult 행에 ArrayIndexOutOfBounds가 나타납니다. = wordNet.getWordNetPath (groupList.get (i)) 그리고 (wordResult.length == 0이면) 줄에 nullPointer가 생깁니다. 들여 쓰기에 대해 죄송합니다. 코딩을 마친 후에는 모두 수정합니다. . 이상한 방법이지만 그것을하는 방법. – user3469624