您能帮我这个错误吗?
我试图使用Aslist()来填充阵列列表,但是II无法理解Eclipse给我的错误,我读了其他解决方案,但我不知道将它们用于我的情况
package arraylistvirtuale;
import java.util.ArrayList;
import java.util.Arrays;
public class BankAccountArraylisttester {
public static void main(String[] args) {
BankAccount cc = new BankAccount(1115);
ArrayList<BankAccount> accounts
= new ArrayList<BankAccount>(Arrays.asList(cc(1115)));
accounts.add(1, new BankAccount(1008));
accounts.remove(0);
System.out.println("size=" + accounts.size());
BankAccount first = accounts.get(0);
System.out.println("first account number=" + first.getAccountNumber());
BankAccount last = accounts.get(accounts.size()-1);
System.out.println("last account number=" + last.getAccountNumber());
BankAccount bankaccount= new BankAccount(2385);
bankaccount.deposit(100.1);
System.out.println("balance =" + bankaccount.getBalance());
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method cc(int) is undefined for the type BankAccountArraylisttester
at arraylistvirtuale/arraylistvirtuale.BankAccountArraylisttester.main(BankAccountArraylisttester.java:11)
I was trying to populate an Arraylist using asList() but I I cant understand the error Eclipse is giving me, I read other solutions but I dont know to use them for my case
package arraylistvirtuale;
import java.util.ArrayList;
import java.util.Arrays;
public class BankAccountArraylisttester {
public static void main(String[] args) {
BankAccount cc = new BankAccount(1115);
ArrayList<BankAccount> accounts
= new ArrayList<BankAccount>(Arrays.asList(cc(1115)));
accounts.add(1, new BankAccount(1008));
accounts.remove(0);
System.out.println("size=" + accounts.size());
BankAccount first = accounts.get(0);
System.out.println("first account number=" + first.getAccountNumber());
BankAccount last = accounts.get(accounts.size()-1);
System.out.println("last account number=" + last.getAccountNumber());
BankAccount bankaccount= new BankAccount(2385);
bankaccount.deposit(100.1);
System.out.println("balance =" + bankaccount.getBalance());
}
}
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method cc(int) is undefined for the type BankAccountArraylisttester
at arraylistvirtuale/arraylistvirtuale.BankAccountArraylisttester.main(BankAccountArraylisttester.java:11)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您已经为变量分配了一个值,请使用此变量。该变量已经包含您写的内容。
或者:
Aslist()方法填写您创建的列表或已经创建的另一个列表。
例如:
If you have already assigned a value to a variable, then use this variable. The variable already contains what you have written to it.
Or:
asList() method fills in either list you have created or another list that has already been created.
For example:
目前尚不清楚您用
arrays.aslist(cc(1115))
- 在Java源中,语法x(y)
是x的调用
,将y
作为参数。因此,错误消息告诉您确切的问题 - 在bank> BankAcccountarraylisttester
类中,没有一个名为cc
的方法cc
。arrays.aslist()
方法将数组作为参数;如果我们忽略(1115)
,您已经将其传递给了单个对象。因此,即使您删除了(1115)
,您也会出现一个错误,表明没有aslist()
方法,以bankaCccountarayListtester
作为一个范围。也许您想将
cc
放入arraylist&lt; bankAccount&gt;
;如果是这样,您可以创建ArrayList,然后向其添加cc
:我已经推测了足够多的 first 和
last
应该是。It is unclear what you intend with
Arrays.asList(cc(1115))
-- in Java source, the syntaxx(y)
is an invocation ofx
, passingy
as a parameter. So the error message is telling you exactly what is wrong -- there is no method namedcc
with an int as a parameter in theBankAccountArraylisttester
class.The
Arrays.asList()
method takes an array as a parameter; you have passed it what looks like an individual object, if we ignore the(1115)
. So even if you remove the(1115)
, you will have an error indicating that there is noasList()
method taking aBankAccountArraylisttester
as a parameter.Perhaps you wanted to put
cc
into anArrayList<BankAccount>
; if so, you can create the ArrayList, then addcc
to it:I've speculated enough without trying to figure out what
first
andlast
are supposed to be.