это может быть глупый вопрос, но я пытаюсь получить доступ к текстовой области из моего нового графического интерфейса через контроллер, который использует свой собственный класс (настолько простой, насколько они есть), когда я запускаю программу, она появляется с не определенным символом. Я не уверен, где я ошибаюсь.
Вот код:
Внешний класс
package dataget;
import java.io.*;
public class ReadWrite {
public void ReadFileContents(String fileName) {
try {
BufferedReader in = new BufferedReader(new FileReader(fileName));
int lineNumber = 0;
int currentLine;
String lines[];
while (in.readLine() != null) {
lineNumber++;
}
in.close();
lines = new String[lineNumber];
BufferedReader inLines = new BufferedReader(new FileReader(fileName));
for (currentLine = 0; currentLine < lineNumber;) {
lines[currentLine] = inLines.readLine();
txtareaOutput.appendText(lines[currentLine]);
currentLine++;
}
inLines.close();
txtareaStatus.appendText("Lines in File: " + lineNumber);
} catch (IOException ioe) {
System.out.println("File not found!");
}
}
А теперь класс контроллера:
public class MainController implements Initializable {
@FXML
private TextField txtName;
@FXML
private TextField txtAge;
@FXML
private ComboBox comboGender;
@FXML
private Button btnRead;
@FXML
private Button btnWrite;
@FXML
private TextArea txtareaStatus;
@FXML
private TextArea txtareaOutput;
@FXML
public void clickRead(){
ReadWrite read = new ReadWrite();
read.ReadFileContents("data/dylans/data.txt");
}
}
Я пропустил несколько строк, поскольку они не имеют значения (все они находятся в одном пакете DataGet).
И я продолжаю получать «ошибка: не могу найти символ»:
Compiling 2 source files to C:\Apps\NetBeans 7.3.1\Dylans Projects\DataGet\build\classes
C:\Apps\NetBeans 7.3.1\Dylans Projects\DataGet\src\dataget\ReadWrite.java:28:
error: cannot find symbol txtareaOutput.appendText(lines[currentLine]);
symbol: variable txtareaOutput
location: class ReadWrite
C:\Apps\NetBeans 7.3.1\Dylans Projects\DataGet\src\dataget\ReadWrite.java:34:
error: cannot find symbol txtareaStatus.appendText("Lines in File: " + lineNumber);
symbol: variable txtareaStatus
location: class ReadWrite 2 errors
Должен ли я объявлять текстовое поле в исходном файле класса, из которого создается объект?
Спасибо.