나는이 코드가 무엇이 잘못되었는지 알아 내려고 정말로 노력하고있다. .add() 및 .toArray()에는 그 아래에 빨간색 선이 있습니다. 이 두 줄을 쓰는 것에 대한 대안이 있습니까? 내가 도대체 뭘 잘못하고있는 겁니까?자바 초보자 : 단어 검색 코드로 파일을 읽는 중. .add()와 .toArray()가 에러를 내고있다.
package prog3;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class WordList {
private String filename;
private Word[] words;
public WordList(String fileName) {
this.filename = fileName;
}
//reads in list of words and stores them internally. line by line
//if method reas list of words successfully, then it returns as true, otherwise false
public boolean readFile() {
try{
BufferedReader read;
read = new BufferedReader(new FileReader(filename));
String nextLine;
while ((nextLine = read.readLine())!= null) {
nextLine = nextLine.trim();
read.add(new Word(nextLine));
}
words = read.toArray(new Word[0]);
}catch(IOException ex){
System.out.println("Caught exception: " +ex.getMessage());
return false;
}
return true;
}
//getList is supposed to return the list of words as an array of class Word. How do I do this???
public Word[] getList() {
}
}
빨간 선 위에 마우스를 올려 놓았을 때 나타나는 오류는 무엇입니까? – hexafraction
기호 심볼을 찾을 수 없습니다. 메서드 toArray (Word [])) 위치 : BufferedReader 유형의 변수 읽기 – DanielleElizabeth
버퍼링 된 판독기가 아닌 ArrayList에 'add (')를 호출해야합니다 – hexafraction