2013-01-05 56 views
-4

我在我的java代碼中有一個小問題。錯誤是令牌令牌上的Java語法錯誤「;」預計

語法錯誤 「;」,預計

這裏是我的代碼:

package natchly.chest; 

import natchly.chest.blocks.BlockStoneChest; 
import net.minecraft.block.Block; 
import cpw.mods.fml.common.Mod; 
import cpw.mods.fml.common.Mod.Init; 
import cpw.mods.fml.common.network.NetworkMod; 
import cpw.mods.fml.common.registry.GameRegistry; 
import cpw.mods.fml.common.registry.LanguageRegistry; 
import cpw.mods.fml.common.event.FMLInitializationEvent; 

@Mod(modid="chestsplus", name="Chests+", version="1.4.6_01") 
@NetworkMod(clientSideRequired=true, serverSideRequired=false) 
public class ModChests { 

    public int idBlockStoneChest = 250; 
    public static Block blockStoneChest; // <-------- Error here 
    blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F); 
    @Init 
    public void init(FMLInitializationEvent e) { 
     GameRegistry.registerBlock(blockStoneChest); 
     LanguageRegistry.addName(blockStoneChest, "Stone Chest"); 
    } 

} 
+4

StackOverflow不是語法檢查服務。 –

+0

但我認爲,它的代碼是正確的... – sofalse

+0

@ user1798217如果代碼是正確的,那麼爲什麼會有語法錯誤 –

回答

3

做這一點:

public static Block blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F); 

或者這樣:

public static Block blockStoneChest; <-------- Error here 
static { 
    blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F); 
} 
3

將這兩行組合成一個聲明和實例化步驟。除非是在方法中,否則Java中不允許使用它。

public static BlockStoneChest blockStoneChest = new BlockStoneChest(idBlockStoneChest).setBlockName("blockNAZWABLOKU").setHardness(1.5F).setResistance(5.0F); 
相關問題