gpt4 book ai didi

java.lang.ClassNotFoundException : SavingAccount 异常

转载 作者:行者123 更新时间:2023-11-30 05:51:34 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
ClassnotFound exception using java reflection

我在执行以下代码时遇到异常,java.lang.ClassNotFoundException: SavingAccount:

public class AccountFactory {   
public void getAccount()
{
IAccount account;
account = null;
try
{
account = (IAccount)Class.forName("SavingAccount").newInstance();
account.Deposit(500);
}
catch(Exception e)
{
System.out.println(e.toString());
}
}

}

导致错误的可能原因是什么?

这是我的储蓄账户代码:

public class SavingAccount implements IAccount {
int money;
SavingAccount()
{
money =0;
}
public void WithDraw(int m)
{
money--;
}
public void Deposit(int m)
{
money++;
System.out.println(money);
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com