我真的不明白我的程序正在發生什麼。我調用[另一個類]的方法,並以某種方式[調用該方法的類]停止了調用的地方,並且不執行程序的其餘部分。從另一個班級調用方法停在該語句
沒有錯誤彈出或者,它只是簡單地didnt運行,其餘(經過與打印語句)
這裏是我的代碼:
類調用該方法
Banana ban = new Banana();
String[] listOfBananas = ban.getBananas(); //Stops at this statement
//Below is a check that never gets executed as with the rest of the program
System.out.println("I didnt get to this statement");
//Do other stuff with the array...
有方法的類
public class Banana {
public static String[] giveOtherClassList;
public Banana(){
}
public static void main(String[] args) {
StringBuilder a = new StringBuilder();
a.append("text text1 text2 text3");
giveOtherClassList = a.toString().split(" "); //Split will create an array
}
public String[] getBananas() {
//I know this method works because I ran this program with
//giveOtherClassList[3] and it returned the correct value
return giveOtherClassList;
}
}
你可能已經用'檢查打印語句「...但你有沒有'調試'? –
難道你是在'Banana'中執行'main'方法而不是你想要執行的'main'方法嗎?而且,你有一些語法錯誤:Bananas ban = ...''Banana ban = ...'和'giveOtherclassList'聲明在一個類的外部) – Turing85
giveOtherClassList數組在聲明類Banana之外聲明? – John