本文介紹了執行任務';失敗:編譯Java';。-本系列第三期的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在此問題因已被提出而關閉之前,據我所知,這是一個模糊且常見的錯誤,因此此問題與其他問題不同。
我通過安裝略微不同的Forge版本修復了以前post中的錯誤,但現在已達到this tutorial的第5步。當我將.gradlew構建與示例mod一起使用時,一切似乎都運行得很好(盡管我找不到控制臺輸出),但當我將mod編輯為作者的描述時,我收到了許多錯誤。
示例mod:
package com.example.examplemod;
import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
public static final String MODID = "examplemod";
public static final String VERSION = "1.0";
@EventHandler
public void init(FMLInitializationEvent event)
{
// some example code
System.out.println("DIRT BLOCK >> "+Blocks.dirt.getUnlocalizedName());
}
}
我是如何按照教程進行更改的:
package com.example.examplemod;
import net.minecraft.init.Blocks;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
@Mod(modid = ExampleMod.MODID, version = ExampleMod.VERSION)
public class ExampleMod
{
public static final String MODID = "examplemod";
public static final String VERSION = "1.1";
@EventHandler
public void init(FMLInitializationEvent event)
{
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
GameRegistry.registerBlock(amethystOre, "amethystOre");
}
private class ModBlock extends Block
{
public ModBlock(Material material, String blockName)
{
super(material);
this.setBlockName(blockName);
this.setBlockTextureName(MODID + ":" + blockName);
this.setCreativeTab(CreativeTabs.tabBlock);
}
}
}
當我運行.gradlew生成時,我收到:
#################################################
ForgeGradle 1.2-SNAPSHOT-fb514d3
https://github.com/MinecraftForge/ForgeGradle
#################################################
Powered by MCP unknown
http://modcoderpack.com
by: Searge, ProfMobius, Fesh0r,
R4wk, ZeuX, IngisKahn, bspkrs
#################################################
:compileApiJava UP-TO-DATE
:processApiResources UP-TO-DATE
:apiClasses UP-TO-DATE
:sourceMainJava UP-TO-DATE
:compileJava
warning: [options] bootstrap class path not set in conjunction with -source 1.6
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:21: error: cannot find symbol
private class ModBlock extends Block
^
symbol: class Block
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:23: error: cannot find symbol
public ModBlock(Material material, String blockName)
^
symbol: class Material
location: class ExampleMod.ModBlock
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: class Block
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:17: error: cannot find symbol
Block amethystOre = new ModBlock(Material.rock, "amethystOre");
^
symbol: variable Material
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:18: error: cannot find symbol
GameRegistry.registerBlock(amethystOre, "amethystOre");
^
symbol: variable GameRegistry
location: class ExampleMod
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:26: error: cannot find symbol
this.setBlockName(blockName);
^
symbol: method setBlockName(String)
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:27: error: cannot find symbol
this.setBlockTextureName(MODID + ":" + blockName);
^
symbol: method setBlockTextureName(String)
C:UsersenjiMinecraftWorkspaceforge-1.7.10-10.13.4.1558-1.7.10-srcuildsourcesjavacomexampleexamplemodExampleMod.java:28: error: cannot find symbol
this.setCreativeTab(CreativeTabs.tabBlock);
^
symbol: variable CreativeTabs
location: class ExampleMod.ModBlock
8 errors
1 warning
:compileJava FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
我對Java了解不多(我剛剛開始學習),但我認為逐個字符復制教程應該會產生一個沒有錯誤的程序。顯然不是。
查看編譯器上的錯誤輸出,第一個錯誤是‘導入網絡無法解析’(第3行),但我不知道原因。
任何幫助都非常感謝,
本
推薦答案
(來自評論)
導入錯誤。您應該使用net.minecraft.*
而不是net.minecraft.init.*
:
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
這篇關于執行任務';失敗:編譯Java';。-本系列第三期的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,