[英]Loading text file data into JTextfield
我已經搜索了兩天的各種教程以完成此代碼,但是它們都沒有真正幫助我理解我的代碼有什么問題的概念。
我試圖寫一個文本文件,然后從它讀到一個Jtable中。 我正在使用數組。 我的教練告訴我,我使用的列表太多-因此我嘗試僅使用一個'constructorList',現在無法編譯。
顯示的錯誤是:
error: method readFile in class CQUPestGUI cannot be applied to given types;
readFile();
required: ArrayList<String>
found: no arguments
reason: actual and formal argument lists differ in length
1 error
就我而言,任何糾正它的嘗試只會使它變得更糟。
這是似乎與錯誤相關的代碼部分。
private void buttonLoadStoredContractsActionPerformed(java.awt.event.ActionEvent evt) {
readFile();
}
我跳過了一些部分,以免提供大量代碼以供閱讀
protected void readFile(ArrayList<String> listContractors)
{
BufferedReader reader = null;
//ArrayList showContract = new ArrayList();
try
{
reader = new BufferedReader(new FileReader("Pest.txt"));
String nLine = reader.readLine();
while (nLine != null)
{
listContractors.add(nLine);
String [] rows = nLine.split("-");
for (String s: rows)
{
System.out.println(s);
}
nLine = reader.readLine();
}
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
displayStoredContracts(listContractors);
}
protected void displayStoredContracts(ArrayList<String> listContractors)
{
for (int i = 0; i < listContractors.size(); i++)
{
txtAreaSavedContracts.append((String) listContractors.get(i));
}
}
如果有人不希望看到整個代碼,這是引擎收錄- 完整的代碼 。 我使用的是gui生成器,因為我只是一個初學者,而且要滿足截止日期-因此,其中很多都會很混亂。 我只是在需要時才提出來。
很容易找到,您的方法簽名說, protected void readFile(ArrayList<String> listContractors)
的方法protected void readFile(ArrayList<String> listContractors)
僅接受String
類型的java.util.ArrayList
。 但是,當您調用該方法時,您沒有傳遞任何參數,而是通過readFile();
調用該方法readFile();
。 您應該已經傳遞了ArrayList作為方法參數。
ArrayList<String> list= new ArrayList<String>();
list.add("asd");
(根據您的要求) readFile(list)
; 希望對您有幫助。
注意:我認為方法readFile
的定義不正確。 它不應該具有ArrayList<String>
作為形式參數。 它必須在方法塊內創建此ArrayList
的實例,並在方法邊界內向其添加元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.