java.lang.NoSuchMethodError明显存在

时间:2015-07-18 11:23:07

标签: java exception constructor bukkit

一般信息:我在版本git-Spigot-1d14d5f-ba32592(MC:1.8.3)中使用Bukkit / Spigot API(实现API版本1.8.3-R0.1-SNAPSHOT ),IntelliJ IDEA 14.1.3并使用其默认编译器进行编译。 java jdk版本是1.8.0_25。

因此,当我尝试调用此类的构造函数时,它会从标题中抛出运行时异常。

库存菜单类

package me.lakan.util.inventory;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.HashMap;
import java.util.Map;

@SuppressWarnings("unused") // Util functionality is not always used
public class InventoryMenu implements Listener {

    private InventoryType type;
    private String title;

    private Map<Integer, MenuOption> options;

    // Constructors
    public InventoryMenu(InventoryType type, String title, JavaPlugin plugin) {

        this.options = new HashMap<Integer, MenuOption>();
        this.type = type;
        this.title = title;

        plugin.getServer().getPluginManager().registerEvents(this, plugin);
    }

    public boolean addOption(int position, MenuOption option) {
        boolean res = isPosEmpty(position);
        this.options.put(position, option);

        return res;
    }

    public void addOption(String name, int position, ItemStack icon) {
        addOption(position, new MenuOption(icon, name));
    }

    public boolean isPosEmpty(int position) {
        return !this.options.containsKey(position);
    }

    public void openFor(Player p) {
        // Create a new inventory
        Inventory inv = Bukkit.createInventory(p, this.type, this.title);

        // Fill all icons at their positions
        for (Map.Entry<Integer, MenuOption> key : this.options.entrySet()) {
            inv.setItem(key.getKey(), key.getValue().getIcon());
        }

        // If the inventory is a player inventory, update the player's
        if (inv.getType() == InventoryType.PLAYER) {
            p.getInventory().setContents(inv.getContents());
        }
        // For any openable inventory, just open it up
        else {
            p.openInventory(inv);
        }
    }

    /**
     * Listens for inventory clicks
     * If the inventory is a menu:
     * - Cancel movement
     * - Push event
     * - Close inventory if it should
     * @param e The actual event
     */
    @EventHandler(priority = EventPriority.HIGHEST)
    public void onInventoryClick(InventoryClickEvent e) {

        // Prevent clicking if this inventory was clicked
        if (e.getClickedInventory().getName().equals(this.title)) {
            e.setCancelled(true);

            // Check for option
            if (this.options.containsKey(e.getRawSlot())) {
                // Get the option for this slot
                MenuOption option = this.options.get(e.getRawSlot());

                // Fill out an event and push it
                MenuClickEvent event = new MenuClickEvent((Player) e.getWhoClicked(), true, option.getName(), e.getRawSlot());
                Bukkit.getServer().getPluginManager().callEvent(event);

                // Now close inventory if not cancelled
                if (event.willCLose()) {
                    e.getWhoClicked().closeInventory();
                }
            }
        }
    }

    @SuppressWarnings("unused")
    public interface OptionClickEventHandler {
        public void onOptionClick(MenuClickEvent event);
    }
}

项目菜单类

package me.lakan.test;

import me.lakan.util.inventory.InventoryMenu;
import me.lakan.util.inventory.MenuClickEvent;
import me.lakan.util.inventory.MenuOption;
import me.lakan.util.item.ItemBuilder;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;

public class ItemMenu implements Listener {
    private PluginEntry plugin;
    private InventoryMenu menu;

    // Commands
    private TestCommand testCmd;

    public ItemMenu(PluginEntry plugin) {

        Validate.notNull(this.plugin, "The plugin reference may not be null");
        this.plugin = plugin;

        this.menu = new InventoryMenu(InventoryType.CHEST, "" + ChatColor.DARK_GRAY + "Abilities", this.plugin);

        // Test
        this.menu.addOption(1,
                new MenuOption(
                        new ItemBuilder()
                                .amount(1)
                                .material(Material.RAW_FISH)
                                .name(ChatColor.LIGHT_PURPLE + "Test")
                                .lore(ChatColor.WHITE + "Click me")
                                .build(),
                        "TestIdentifier"));
        this.testCmd= new TestCmd(this.plugin);
}

    public void openFor(Player p) {
        this.menu.openFor(p);
    }



    @EventHandler(priority = EventPriority.NORMAL)
    public void onOptionClick(MenuClickEvent e) {
        // Test
        if (e.getName().equals("TestIdentifier")) {
            this.testCmd.executeFor(e.getWhoClicked());
        }
    }
}

异常堆栈跟踪

  

[12:48:25] [服务器线程/错误]:启用Test v1.0时出错(是否为最新版本?)   java.lang.NoSuchMethodError:me.lakan.util.inventory.InventoryMenu。(Lorg / bukkit / event / inventory / InventoryType; Ljava / lang / String; Lorg / bukkit / plugin / java / JavaPlugin;)V

     

at me.lakan.test.ItemMenu。(ItemMenu.java:33)〜[?:?]     在me.lakan.test.CommandParser。(CommandParser.java:20)〜[?:?]     在me.lakan.test.PluginEntry.onEnable(PluginEntry.java:21)〜[?:?]     在org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)〜[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.java:356)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在org.bukkit.craftbukkit.v1_8_R2.CraftServer.enablePlugins(CraftServer.java:316)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     at net.minecraft.server.v1_8_R2.MinecraftServer.r(MinecraftServer.java:416)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     at net.minecraft.server.v1_8_R2.MinecraftServer.k(MinecraftServer.java:382)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     at net.minecraft.server.v1_8_R2.MinecraftServer.a(MinecraftServer.java:337)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在net.minecraft.server.v1_8_R2.DedicatedServer.init(DedicatedServer.java:257)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:522)[spigot_server.jar:git-Spigot-1d14d5f-ba32592]     在java.lang.Thread.run(未知来源)[?:1.8.0_31]

正如你所看到的那样,构造函数在那里,并且据我所知正确调用。那么这个错误在我的项目设置,API事物或完全不同的东西中是错误的吗?

实用程序类位于一个单独的模块中,如果我将它们粘贴到我的测试插件模块中,一切都可以工作,但不能在其他模块中。但是, me.lakan.util.inventory 中任何其他类中的任何其他构造函数都可以正常调用。

1 个答案:

答案 0 :(得分:3)

问题出在项目结构中。

对于测试工件,我选择了util模块的模块输出。 将其更改为util模块的工件输出可修复它。