我不知道我的程序有什麼問題。本質上,我只想成爲我班的一個對象。然後,該對象應該在其構造函數內創建另一個對象。但是,當我從第一個對象的構造函數中創建的對象,我得到的錯誤:我得到一個StackOverflowError遞歸調用相同的錯誤
"Exception in thread "main" java.lang.StackOverflowError at Setup.(Setup.java:31) at GameController.(GameController.java:30)"
錯誤的這一部分重複,直到我運行「錯誤」盒已滿:
"at Setup.(Setup.java:31)
at GameController.(GameController.java:30)"
這裏是我的代碼(即在主創建的對象)
public class GameController {
GameController() {
Setup Set = new Setup(); //Refers to error happening here.
(設置對象類)
public class Setup extends GameController {
Setup() { //Refers to error happening here.
我不介意以不同方式執行我的代碼,但我想知道我在做什麼錯誤,所以我可以在將來做對。
做出決定。 *要麼你得到一個'StackOverflowException' *或者*它不能編譯。這兩者是相互排斥的。 – EJP 2015-03-19 00:56:39