2011-11-03 91 views
0

我試圖將輸出傳遞給文本區域。在Java中將數據從一個類傳遞到另一個類

我有Class Search它處理所有的搜索和顯示輸出使用System.out.println()

我已經創建了Class GUI以使控制檯輸出(System.out.println())出現在JTextArea中。

我想通過使用對象將數據傳遞到文本區域,但我不知道它爲什麼不工作。

Class Search有這種方法,計算輸出:

public static void searchIndex(String searchString) throws IOException, ParseException 

Class GUItext1

課堂GUI我已經試過這樣:

text1.setText(Search.searchIndex(searchString)); 

,但它給我一個錯誤searchString cannot be resolved to a variable

有什麼建議嗎?

問候。

+1

是;從Java教程開始:http://download.oracle.com/javase/tutorial/ –

回答

2

方法沒有返回:

public static void searchIndex(String searchString) throws IOException, ParseException { 

需要改變voidString,並返回結果:

public static String searchIndex(String searchString) throws IOException, ParseException { 
    //do search 
    return resultString; 
} 

對於以下工作:

text1.setText(Search.searchIndex(searchString)); 
+0

感謝您的回覆,我也嘗試了這一點。仍然顯示相同的錯誤。 – HShbib

+0

@HumamShbib:你需要發佈'Search'類的代碼。 –

+0

這裏是我使用的演示http://www.avajava.com/tutorials/search/how-do-i-use-lucene-to-index-and-search-text-files/LuceneDemo.java – HShbib

0

searchString無法解析d到變量

上述錯誤是由於您試圖在不聲明它的情況下使用變量「searchString」而引起的。

String searchString = "Some string that is in the search index"; 
text1.setText(Search.searchIndex(searchString)); 
+0

爲您的答覆thinks,我試過它仍然是一樣的錯誤。 – HShbib

相關問題