该方法必须覆盖或实现超类型方法

时间:2014-09-29 23:21:29

标签: java minecraft minecraft-forge

我正在制作一个自定义盔甲,在我的盔甲课中我收到了这个错误:

  

ArmorE类型的方法getArmorTexture(ItemStack,Entity,int,int)必须覆盖或实现超类型方法

为什么我收到此错误?

这是我的代码:

护甲等级:

package com.domoq.EmeraldGear.armor;

import com.domoq.EmeraldGear.EmeraldGearMod;

import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;

public class ArmorE extends ItemArmor {

    public ArmorE(ArmorMaterial part2ArmorE, int part3, int part4) {
        super(part2ArmorE, part3, part4);
        this.setCreativeTab(CreativeTabs.tabCombat);
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, int type) {
        if (stack.getItem() == EmeraldGearMod.EmeraldHelmet || stack.getItem() == EmeraldGearMod.EmeraldChest || stack.getIconIndex() == EmeraldGearMod.EmeraldBoots) {
            return "emeraldgearmod:textures/models/armor/ArmorL1.png";
        } else if (stack.getItem() == EmeraldGearMod.EmeraldLegs) {
            return "emeraldgearmod:textures/models/armor/ArmorL2.png";
        } else return null;
    }
}

主类的一部分:

//Armor Material
public static ArmorMaterial ArmorE = EnumHelper.addArmorMaterial("AEmerald", 29, new int[]{3, 7, 4, 2}, 25);

//Armor Items
public static Item EmeraldHelmet = new ArmorE(ArmorE, 2, 0).setUnlocalizedName("EmeraldHelmet").setTextureName("emeraldgearmod:emerald_helmet");
public static Item EmeraldChest = new ArmorE(ArmorE, 2, 1).setUnlocalizedName("EmeraldChest").setTextureName("emeraldgearmod:emerald_chestplate");
public static Item EmeraldLegs = new ArmorE(ArmorE, 2, 2).setUnlocalizedName("EmeraldLegs").setTextureName("emeraldgearmod:emerald_leggings");
public static Item EmeraldBoots = new ArmorE(ArmorE, 2, 3).setUnlocalizedName("EmeraldBoots").setTextureName("emeraldgearmod:emerald_boots");

9 个答案:

答案 0 :(得分:14)

如果您使用的是Eclipse,请尝试关闭并再次打开它。错误消失了。

答案 1 :(得分:5)

要覆盖方法,签名需要与super class的签名匹配。取代

public String getArmorTexture(ItemStack stack, Entity entity, int slot, int type) {

public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type) {

答案 2 :(得分:3)

这意味着您不需要覆盖注释,因为您没有覆盖或实现该方法的某些内容。因此,您应该只删除

@Override

答案 3 :(得分:2)

我是被Google搜索带到这里的,虽然这对OP毫无帮助(因为显然他们的问题已在公认的答案中得到了解决),但我想与潜在的未来访问者分享我的问题。

我迷失了方向-我正在与Jetty合作,并且所采用的方法无法接受Override注释。我什至从基类复制并粘贴了它,以确保我没有以某种方式破坏方法签名。尽管许多答案都忽略了它,但这是websocket的切入点,并且没有触发-显然,我不能忽略这一点!

最终结果是导入-我从错误的包中导入了会话-从Jetty包中导入了会话,因此它看起来确实合法,但是当我有org.eclipse.jetty.websocket.api.Session时我需要有org.eclipse.jetty.server.session.Session进口。未来的访问者不太可能会有配对的不匹配包裹进口,但是我怀疑有些人会乘我刚乘的船。

答案 4 :(得分:0)

在定义的界面ItemArmor中,删除尖括号中的所有通用类型。

答案 5 :(得分:0)

如果您正在使用Java Spring Framework,则必须通过在您的<context:annotation-config/>文件中写入config.xml来提供注释的使用,以便能够使用诸如@Override之类的注释, @Component@Value等。

右键单击您的软件包,然后创建一个.xml(即config.xml)文件进行配置(如果不存在)。

并在其中添加以下代码。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- This allows annotations -->
    <context:annotation-config />


</beans>

答案 6 :(得分:0)

您可能没有在Interface或Base-Class中保存的内容。这就是删除注释@Override可以清除错误的原因。

答案 7 :(得分:0)

如果您检查了超类/接口的签名是否匹配,但仍然出现错误。尝试先保存超类/接口。

答案 8 :(得分:0)

OP 的问题已经解决,但对于未来的访问者,我想说我遇到了这个错误,问题在于类型参数。

代替

field.addValueChangeHandler(new ValueChangeHandler<FieldType>() {
        @Override
        public void onValueChange(ValueChangeEvent<FieldType> event) {
            Window.alert("[DEBUG] I'm here");
        }
    });

我应该写

field.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            Window.alert("[DEBUG] I'm here");
        }
    });

我花了一段时间才找到解决方案,因为错误消息似乎没有提到这个。