2017-09-23 108 views
0

無法創建塊裝載票我試圖用一種門票:在鍛造

Ticket ticket = ForgeChunkManager.requestTicket(this, this.minecraftServer.entityWorld, ForgeChunkManager.Type.NORMAL); 

上面的代碼是在我的主模類。當我嘗試運行我的mod時,我得到一個NullPointerException。

回答

0

在這種情況下,this.minecraftServerthis.minecraftServer.entityWorldnull

嘗試用if語句包圍它。

if (this.minecraftServer != null && this.minecraftServer.entityWorld != null){ 
    Ticket ticket = ForgeChunkManager.requestTicket(this, 
                this.minecraftServer.entityWorld, 
                ForgeChunkManager.Type.NORMAL); 
} 

和調試的目的,我建議你在兩個條件分開吧:

if (this.minecraftServer == null) { 
    System.out.println("minecraftServer is null"); 
    //or do anything can to warn you 
} else if(this.minecraftServer.entityWorld == null) { 
    System.out.println("entityWorld is null"); 
    //or do anything can to warn you 
} else { 
    Ticket ticket = ForgeChunkManager.requestTicket(this, 
                this.minecraftServer.entityWorld, 
                ForgeChunkManager.Type.NORMAL); 
} 

除非你能使用調試器來檢查值。

但是沒有完整的代碼,就不可能知道是否有其他錯誤。