gpt4 book ai didi

java - 任务  ':compileJava' 执行失败

转载 作者:太空宇宙 更新时间:2023-11-04 09:21:40 25 4
gpt4 key购买 nike

我正在尝试制作一个 Minecraft 模组,它应该能让 bat 掉落生鸡肉。 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确实打开了,但是当它进入compileJava阶段时,它在控制台中显示以下错误消息:

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 类名称不匹配。 Java 源文件名和文件中类的 Java 类名必须匹配。这就是 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 指令。这是涉及类型的“未找到符号”错误的最可能原因。看起来您有几种“找不到符号”的情况,这可能是由于缺少 import 文件造成的,例如:

  • class LivingDropsEvent 是未找到的符号
  • class itemStack 是未找到的符号
  • class EntityItem 是未找到的符号

也没有找到变量items。我认为它也是一个全局变量,可能也在 import 文件中。

查看 Jabelar 的 Minecraft Forge Modding 教程这篇文章,Minecraft Forge 1.7.2/1.7.10 Changing Drops of Vanilla Entities以及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.

这些警告可能重要也可能不重要。如果它们来自您从某个图书馆使用的某个来源,您可能无法解决这些问题。无论这些警告如何,您的应用程序都可以正常运行。

关于java - 任务  ':compileJava' 执行失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58252713/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com