这可能是一个愚蠢的问题,但是当我运行程序时,我试图通过控制器从我的新 Gui 访问一个文本区域,该控制器使用它自己的类(尽管它们很简单),但它会出现未定义的符号。我不确定我哪里出错了。
这是代码:
外部类
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
我是否必须在创建对象的原始类文件中声明文本区域?
谢谢。