我正在爲我的任務創建銀行應用程序,我想知道是否可以從if/else語句調用另一個類?如果是的話,我哪裏錯了?因爲在編譯之前,我不會遇到任何錯誤,但在嘗試運行時會出現很多錯誤。我想在currentAccount.java類中調用「public void currentAccountCreate」。我也有一個主菜單頁面。 非常感謝如何從if/else語句中調用不同的類?
import java.util.Scanner;
public class Account {
Scanner keyboard = new Scanner(System.in);
currentAccount currentAccountCreating = new currentAccount();
//savingsAccount savingsAccountCreating = new savingsAccount();
public void accountCreation(){
String createOption = "";
boolean valid = false;
while (!valid) {
System.out.println("What account would you like to create?");
System.out.println("Current or savings?");
createOption = keyboard.nextLine();
if (createOption.equalsIgnoreCase("current")) {
currentAccountCreating.currentAccountCreate();
} else {
System.out.println("Invalid account type selected. Please enter checking or savings");
}
}
}
}
這裏的我想叫什麼
public class currentAccount extends Account {
public void currentAccountCreate() {
錯誤堆棧跟蹤
Exception in thread "main" java.lang.StackOverflowError
at java.util.Currency.getInstance(Unknown Source)
at sun.util.locale.provider.DecimalFormatSymbolsProviderImpl.getInstance(Unknown Source) at java.text.DecimalFormatSymbols.getInstance(Unknown Source)
at assignmentmine.Account.<init>(Account.java:7)
at assignmentmine.currentAccount.<init>(currentAccount.java:5)
// Plus a load more related ones
發佈錯誤.. –
異常線程 「main」 java.lang.StackOverflowError的 \t在java.util.Currency.getInstance(來源不明)在sun.util.locale.provider.DecimalFormatSymbolsProviderImpl.getInstance(未知源) \t位於assignmentmine.Account的java.text.DecimalFormatSymbols.getInstance(Unknown Source)。(Account.java:7) \t at assignmentmine.currentAccount。 (currentAccount.java:5)加載更多相關的文件 –
R0ckTillWeDr0p
您必須編輯問題以包含currentAccount的內容。它看起來像你傳遞一些無效的東西到一些貨幣方法 –