【发布时间】:2013-08-28 19:09:10
【问题描述】:
这可能是一个愚蠢的问题,但我试图通过控制器从我的新 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
我必须在创建对象的原始类文件中声明 textarea 吗?
谢谢。
【问题讨论】:
-
“我不断收到“错误:找不到符号”。” => 何时、如何、在哪里?编译的时候?在哪条线上?等
-
这是确切的错误输出:- 将 2 个源文件编译到 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: 错误:找不到符号 txtareaOutput.appendText(lines[currentLine]);符号:变量 txtarea 输出位置:类 ReadWrite C:\Apps\NetBeans 7.3.1\Dylans Projects\DataGet\src\dataget\ReadWrite.java:34:错误:找不到符号 txtareaStatus.appendText("文件中的行:" + lineNumber );符号:变量 txtareaStatus 位置:类 ReadWrite 2 错误
-
请尝试在您的问题中直接包含所有相关信息。我已经添加了详细信息。