我尝试使用以下方式制作门票:
Ticket ticket = ForgeChunkManager.requestTicket(this, this.minecraftServer.entityWorld, ForgeChunkManager.Type.NORMAL);
上面的代码在我的主mod类中。当我尝试运行我的mod时,我得到一个NullPointerException。
答案 0 :(得分:0)
在这种情况下,this.minecraftServer
或this.minecraftServer.entityWorld
null 。
尝试用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);
}
除非您可以使用调试器来检查值。
但如果没有完整的代码,就不可能知道是否还有其他错误。