在Java中将数据从一个类传递到另一个类
我正在尝试将输出传递到文本区域 我有在Java中将数据从一个类传递到另一个类,java,Java,我正在尝试将输出传递到文本区域 我有类Search,它使用System.out.println()处理所有搜索并显示输出 我创建了类GUI,以使控制台输出(System.out.println())显示在JTextArea中 我正在尝试使用对象将数据传递到文本区域,但我不知道为什么它不起作用 类搜索具有计算输出的方法: public static void searchIndex(String searchString) throws IOException, ParseException
类Search
,它使用System.out.println()
处理所有搜索并显示输出
我创建了类GUI
,以使控制台输出(System.out.println())
显示在JTextArea
中
我正在尝试使用对象将数据传递到文本区域,但我不知道为什么它不起作用
类搜索
具有计算输出的方法:
public static void searchIndex(String searchString) throws IOException, ParseException
classgui
具有text1
在类GUI中,我尝试了以下方法:
text1.setText(Search.searchIndex(searchString));
但它给了我一个错误searchString无法解析为变量
有什么建议吗
注意。方法未返回:
public static void searchIndex(String searchString) throws IOException, ParseException {
需要将void
更改为String
,并返回结果:
public static String searchIndex(String searchString) throws IOException, ParseException {
//do search
return resultString;
}
为使以下各项发挥作用:
text1.setText(Search.searchIndex(searchString));
searchString无法解析为变量
上面的错误是由于您试图使用变量“searchString”而没有声明它
String searchString = "Some string that is in the search index";
text1.setText(Search.searchIndex(searchString));
对从Java教程开始:谢谢你的回复,我也试过了。仍然显示相同的错误。@HumamShbib:您需要发布
搜索类的代码。这是我正在使用的演示