簡體   English   中英

java.lang.NoSuchMethodError當它明顯存在時

[英]java.lang.NoSuchMethodError when it is clearly there

常規信息:我正在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] [服務器線程/錯誤]:啟用測試v1.0時發生錯誤(是否最新?)java.lang.NoSuchMethodError:me.lakan.util.inventory.InventoryMenu。(Lorg / bukkit / event / inventory / InventoryType; Ljava / lang / String; Lorg / bukkit / plugin / java / JavaPlugin;)V

在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) org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.java:356)上的spigot_server.jar:git-Spigot-1d14d5f-ba32592],位於org.bukkit的[spigot_server.jar:git-Spigot-1d14d5f-ba32592]。 .v1_8_R2.CraftServer.enablePlugins(CraftServer.java:316)在net.minecraft.server.v1_8_R2.MinecraftServer.r(MinecraftServer.java:416)[spigot_server.jar:git-Spigot-1d14d5f-ba32592] [spigot_server.jar: git-Spigot-1d14d5f-ba32592],位於net.minecraft.server.v1_8_R2.MinecraftServer.k(MinecraftServe r.java:382)在net.minecraft.server.v1_8_R2.MinecraftServer.a(MinecraftServer.java:337)上的[spigot_server.jar:git-Spigot-1d14d5f-ba32592] [spigot_server.jar:git-Spigot-1d14d5f-ba32592在net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:MinecraftServer.v1_8_R2.DedicatedServer.init(DedicatedServer.java:257)[spigot_server.jar:git-Spigot-1d14d5f-ba32592] 522)[spigot_server.jar:git-Spigot-1d14d5f-ba32592] at java.lang.Thread.run(未知源)[?:1.8.0_31]

如您所見,構造函數就在那里,據我所知正確地被稱為。 那么,這個錯誤是我的項目設置中的錯誤,API還是完全不同的東西?

實用程序類位於單獨的模塊中,如果我將它們粘貼到測試插件模塊中,但不能粘貼到其他模塊中,則一切正常。 但是,可以正常調用me.lakan.util.inventory中任何其他類中的任何其他構造函數。

問題出在項目結構中。

對於測試工件,我選擇了util模塊的模塊輸出 將其更改為util模塊的工件輸出可修復該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM