您能帮我这个错误吗?

发布于 2025-02-04 21:17:57 字数 1279 浏览 2 评论 0原文

我试图使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

樱花细雨 2025-02-11 21:17:58

如果您已经为变量分配了一个值,请使用此变量。该变量已经包含您写的内容。

    BankAccount cc = new BankAccount(1115);
    BankAccount dd = new BankAccount(1234);
    BankAccount ee = new BankAccount(3333);
    ArrayList<BankAccount> accounts
            = new ArrayList<BankAccount>(Arrays.asList(cc, dd, ee));

或者:

   ArrayList<BankAccount> accounts
        = new ArrayList<BankAccount>(Arrays.asList(
   new BankAccount(1234);
   new BankAccount(2222);
   new BankAccount(3333);
   ));

Aslist()方法填写您创建的列表或已经创建的另一个列表。

例如:

 ArrayList<BankAccount> accounts
 = new ArrayList<BankAccount> 
 (Arrays.asList(name_of_another_list));

If you have already assigned a value to a variable, then use this variable. The variable already contains what you have written to it.

    BankAccount cc = new BankAccount(1115);
    BankAccount dd = new BankAccount(1234);
    BankAccount ee = new BankAccount(3333);
    ArrayList<BankAccount> accounts
            = new ArrayList<BankAccount>(Arrays.asList(cc, dd, ee));

Or:

   ArrayList<BankAccount> accounts
        = new ArrayList<BankAccount>(Arrays.asList(
   new BankAccount(1234);
   new BankAccount(2222);
   new BankAccount(3333);
   ));

asList() method fills in either list you have created or another list that has already been created.

For example:

 ArrayList<BankAccount> accounts
 = new ArrayList<BankAccount> 
 (Arrays.asList(name_of_another_list));
倾听心声的旋律 2025-02-11 21:17:58

目前尚不清楚您用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

ArrayList<BankAccount> accounts = new ArrayList<>();
accounts.add(cc);

我已经推测了足够多的 first 和last应该是。

It is unclear what you intend with Arrays.asList(cc(1115)) -- in Java source, the syntax x(y) is an invocation of x, passing y as a parameter. So the error message is telling you exactly what is wrong -- there is no method named cc with an int as a parameter in the BankAccountArraylisttester 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 no asList() method taking a BankAccountArraylisttester as a parameter.

Perhaps you wanted to put cc into an ArrayList<BankAccount>; if so, you can create the ArrayList, then add cc to it:

ArrayList<BankAccount> accounts = new ArrayList<>();
accounts.add(cc);

I've speculated enough without trying to figure out what first and last are supposed to be.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文