好的,我正在尝试从另一个文件中的另一个类中的另一个函数调用 setter 和 getter。这就是我得到的,我真的不知道我做错了什么......
银行.java
package Bank;
import java.io.*;
import java.util.*;
public class Bank
{
public static void main (String args[]) throws FileNotFoundException
{
final String fileName = "Bank/AcctInfo.txt";
File accounts = new File(fileName);
ArrayList <Object> acctInfo = new ArrayList <Object> ();
acctInfo = setObjects(accounts);
}
public static ArrayList setObjects(File document) throws FileNotFoundException
{
ArrayList <Object> objectArray = new ArrayList <Object> ();
Scanner fileInput = new Scanner(document);
String blankInfo;
String accountType;
String customerType;
String customerName;
int accountNumber;
float balance;
int counter = 0;
while (fileInput.hasNext())
{
accountNumber = fileInput.nextInt();
blankInfo = fileInput.nextLine();
accountType = fileInput.nextLine();
customerName = fileInput.nextLine();
customerType = fileInput.nextLine();
balance = fileInput.nextFloat();
blankInfo = fileInput.nextLine();
objectArray.add(new BankAccount());
objectArray.get(counter).setAccNumber(accountNumber);
counter++;
}
return objectArray;
}
}
银行账户.java
package Bank;
public class BankAccount extends Bank
{
private int accNumber;
private String accType;
private String cusName;
private String cusType;
private float bal;
public void setAccNumber(int accountNumber)
{
int accNumber = accountNumber;
}
public int getAccNumber()
{
return accNumber;
}
public void setAccType(String accountType)
{
String accType = accountType;
}
public String getAccType()
{
return accType;
}
public void setCusName(String customerName)
{
String cusName = customerName;
}
public String getCusName()
{
return cusName;
}
public void setCusType(String customerType)
{
String cusType = customerType;
}
public String getCusType()
{
return cusType;
}
public void setBal(float balance)
{
float bal = balance;
}
public float getBal()
{
return bal;
}
}
错误:
Bank.java:51: error: cannot find symbol
objectArray.get(counter).setAccNumber(accountNumber);
^
symbol: method setAccNumber(int)
location: class Object
Note: .\Bank\Bank.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
它还没有完成,但如果有人能帮助我完成那一点,那将是一个巨大的帮助......