2012-12-06 43 views
0

我聲明瞭一個新的「世界」對象另一個類,如下所示:爪哇 - 構造顯然缺失,運營商超載

fray.World world = new fray.World(); 

Java編譯器是抱怨無法找到構造函數(這是罰款該課程在fray包中的位置)。

我已經在fray.World類的構造函數如下:

World() { 
     this(100, 100, 100); 
    } 

    World(int width) { 
     this(width, 100, 100); 
    } 

    World(int width, int length) { 
     this(width, length, 100); 
    } 

    World(int width, int length, int height) { 
     this.x = new int[width]; 
     this.y = new int[length]; 
     this.z = new int[height]; 

     this.entities = new Entity[0]; 
    } 

這是怎麼回事?

+0

從那裏,你想將類實例?同樣的軟件包'fray'還是來自不同的軟件包? – Chan

+0

當前未打包的類。 – gossfunkel

回答

3

您應該更改構造函數的可見性,以便您可以在其他包中使用它們,它們當前具有包級別訪問權限。你可以嘗試製作它們public

+0

我想了一會兒會解決它,但不幸的是,錯誤仍在發生。 – gossfunkel

1

除非Worldstatic inner class,你將需要使用:

fray.World world = new fray().new World(); 
+0

fray是一個包,而不是一個類 - 所以編譯器只是抱怨它無法找到fray類。 – gossfunkel

+0

拼寫的爆炸和完整的類可能有點大 - 這是World.java http://pastebin.com/NuskJeps – gossfunkel

+0

我編譯這個類與Eclipse和與'javac'從一個unpackaged類,並沒有得到編譯錯誤。 – Reimeus