任务 ':compileJava' 执行失败
Execution failed for task ':compileJava'
我正在尝试制作一个 Minecraft mod,它应该能让蝙蝠掉落生鸡肉。 Minecraft 确实启动并实际打开,但是当它进入 compileJava 阶段时,控制台中会显示错误。我对Java知之甚少,所以不知道如何总结
我的问题是这些错误消息是什么意思,我该如何更正它们?
我问过我的一些同事关于这个问题,但他们也不知道。
//NOTE TO SELF: Learn to indent.
package net.mcreator.trevcorp_meat_paste;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraft.world.World;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityBat;
public static class GUIRenderEventClass
{@SubscribeEvent
public void playerKilledBat(livingDropsEvent event)
{
if(event.entityLiving instanceof EntityBat)
{
event.drops.clear();
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
event.entity.posY, event.entity.posZ, itemStackToDrop));
}
}
}
Minecraft 确实打开了,但是当它进入编译Java 阶段时,它会在控制台中显示以下错误消息:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:16: error: class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java
public static class GUIRenderEventClass
^
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol
public void playerKilledBat(livingDropsEvent event)
^
symbol: class livingDropsEvent
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: variable items
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:25: error: cannot find symbol
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
^
symbol: class EntityItem
location: class GUIRenderEventClass
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
第一条错误信息,
class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java public static class GUIRenderEventClass
表示您的 Java 源位于一个文件中,该文件的名称与源代码中的 Java class 名称不匹配。 Java 源文件名和文件中 class 的 Java class 名称必须匹配。 Java 编译器就是这样找到东西的。
您还有一些相同类型的错误,例如:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol public void playerKilledBat(livingDropsEvent event)
这意味着当 Java 编译器处理源代码时,它发现了一个它不知道的符号或类型或某种名称。这是一个错误,表示在 Java 编译器搜索时找不到指定的符号或类型或名称。
发生这种情况有多种原因。
最常见的情况是包含符号或类型或名称的文件缺少 import
指令。这是涉及类型的 "symbol not found" 错误的最可能原因。看起来你有几个 "symbol not found" 的案例,这可能是由于缺少 import
文件,例如:
class livingDropsEvent
是找不到的符号
class itemStack
是找不到的符号
class EntityItem
是找不到的符号
也没有找到变量items
。我认为它可能也是 import
文件中某处的全局变量。
查看 Jabelar 的 Minecraft Forge 改装教程上的这篇文章,Minecraft Forge 1.7.2/1.7.10 Changing Drops of Vanilla Entities as well as Minecraft Modding: Event Handling,了解有关这些符号的一些详细信息。
另请查看 mincraftforge 论坛中的示例代码,https://www.minecraftforge.net/forum/topic/28747-how-to-add-a-drop-to-a-vanilla-mob-1710/ 其中包含这组 import
指令:
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
最后你有一些警告:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
这些警告可能重要也可能不重要。如果它们来自您正在使用的某个图书馆的某个来源,您可能无法解决这些问题。无论这些警告如何,您的应用程序都可以运行。
我正在尝试制作一个 Minecraft mod,它应该能让蝙蝠掉落生鸡肉。 Minecraft 确实启动并实际打开,但是当它进入 compileJava 阶段时,控制台中会显示错误。我对Java知之甚少,所以不知道如何总结
我的问题是这些错误消息是什么意思,我该如何更正它们?
我问过我的一些同事关于这个问题,但他们也不知道。
//NOTE TO SELF: Learn to indent.
package net.mcreator.trevcorp_meat_paste;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraft.world.World;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.passive.EntityBat;
public static class GUIRenderEventClass
{@SubscribeEvent
public void playerKilledBat(livingDropsEvent event)
{
if(event.entityLiving instanceof EntityBat)
{
event.drops.clear();
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
event.entity.posY, event.entity.posZ, itemStackToDrop));
}
}
}
Minecraft 确实打开了,但是当它进入编译Java 阶段时,它会在控制台中显示以下错误消息:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:16: error: class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java
public static class GUIRenderEventClass
^
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol
public void playerKilledBat(livingDropsEvent event)
^
symbol: class livingDropsEvent
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: class itemStack
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:24: error: cannot find symbol
itemStack itemStackToDrop = new itemStack(items.chicken, 1);
^
symbol: variable items
location: class GUIRenderEventClass
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:25: error: cannot find symbol
event.drops.add(new EntityItem(event.entity.worldObj, event.entity.posX,
^
symbol: class EntityItem
location: class GUIRenderEventClass
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
6 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 8s
第一条错误信息,
class GUIRenderEventClass is public, should be declared in a file named GUIRenderEventClass.java public static class GUIRenderEventClass
表示您的 Java 源位于一个文件中,该文件的名称与源代码中的 Java class 名称不匹配。 Java 源文件名和文件中 class 的 Java class 名称必须匹配。 Java 编译器就是这样找到东西的。
您还有一些相同类型的错误,例如:
C:\Users\USER\MCreatorWorkspaces\trevcorp_meat_paste\build\sources\main\java\net\mcreator\trevcorp_meat_paste\MCreatorBatMeat.java:18: error: cannot find symbol public void playerKilledBat(livingDropsEvent event)
这意味着当 Java 编译器处理源代码时,它发现了一个它不知道的符号或类型或某种名称。这是一个错误,表示在 Java 编译器搜索时找不到指定的符号或类型或名称。
发生这种情况有多种原因。
最常见的情况是包含符号或类型或名称的文件缺少 import
指令。这是涉及类型的 "symbol not found" 错误的最可能原因。看起来你有几个 "symbol not found" 的案例,这可能是由于缺少 import
文件,例如:
class livingDropsEvent
是找不到的符号class itemStack
是找不到的符号class EntityItem
是找不到的符号
也没有找到变量items
。我认为它可能也是 import
文件中某处的全局变量。
查看 Jabelar 的 Minecraft Forge 改装教程上的这篇文章,Minecraft Forge 1.7.2/1.7.10 Changing Drops of Vanilla Entities as well as Minecraft Modding: Event Handling,了解有关这些符号的一些详细信息。
另请查看 mincraftforge 论坛中的示例代码,https://www.minecraftforge.net/forum/topic/28747-how-to-add-a-drop-to-a-vanilla-mob-1710/ 其中包含这组 import
指令:
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.boss.EntityWither;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.WeightedRandomChestContent;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.util.EnumHelper;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
最后你有一些警告:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
这些警告可能重要也可能不重要。如果它们来自您正在使用的某个图书馆的某个来源,您可能无法解决这些问题。无论这些警告如何,您的应用程序都可以运行。