[SOLVED] NoSuchMethodError on getMaxHealth

Discussion in 'Plugin Development' started by IDragonfire, Nov 27, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    IDragonfire

    If I try to call the method "getMaxHealth" (from Player) and got an "NoSuchMethodError " Exception ...
    What I am doing wrong? (Bukkit: 1131)

    Here the code:

    Code:
    package com.idragonfire;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class PlayerMaxHealthDemo extends JavaPlugin {
        private Player[] playerStore;
    
        @Override
        public void onDisable() {
            // TODO Auto-generated method stub
        }
    
        @Override
        public void onEnable() {
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                @SuppressWarnings("synthetic-access")
                @Override
                public void run() {
                    PlayerMaxHealthDemo.this.playerStore = Bukkit
                            .getOnlinePlayers();
                    if (PlayerMaxHealthDemo.this.playerStore.length > 0) {
                        System.out.println(PlayerMaxHealthDemo.this.playerStore[0]
                                .getMaxHealth());
                    }
                }
            }, 0, 1);
        }
    }
    
    and the excpection:

    Code:
    2011-11-27 13:11:50 [WARNING] Task of 'PlayerMaxHealthDemo' generated an exception
    java.lang.NoSuchMethodError: org.bukkit.entity.Player.getMaxHealth()I
        at com.idragonfire.PlayerMaxHealthDemo$1.run(PlayerMaxHealthDemo.java:27)
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:137)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:441)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    and the jar for testing (with source) ...
     

    Attached Files:

  2. Offline

    ItsHarry

    PlayerMaxHealthDemo.this ?? o-o

    Just use this. without PlayerMaxHealthDemo in front of it.
     
  3. Offline

    IDragonfire

    No,
    that is correct JAVA and I think that is not the problem ...

    playerStore is a field of the outerclass PlayerMaxHealthDemo and the Runnable is an anonymous inner class with his own fields, and these anonymous class has no field "playerStore" and this.playerStore produce an error ("playerStore cannot be resolved or is not a field" is the error message).
     
  4. Offline

    ImperatorFeles

    I downloaded the jar and tested it, and it worked fine, no exceptions. My guess would be that you're developing with an up to date Bukkit jar, but running a server with an out of date CraftBukkit jar. The method would be found in the the Bukkit jar, but when you try to run it on the server, it can't find it.
     
  5. Offline

    vildaberper

    Are you sure you run an updated version of CB when running your test-server?
     
  6. Offline

    IDragonfire

    LoL ....
    I use the following jar:
    http://ci.bukkit.org/job/dev-CraftBukkit/1337/
    But why Bukkit say it is 1331 oO (MANIFEST.MF)

    Where can I check the Bukkit version?
    and
    Where are the old ApiDocs?
    I am sure I had found a link to choose the api for the right version ...

    Edit:
    Ok,
    I use a new API to dev,
    because
    https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/entity/LivingEntity.java
    hasn't the method "getMaxHealth" Nov 19,2011 ^^
    https://github.com/Bukkit/Bukkit/commits/master/src/main/java/org/bukkit/entity/LivingEntity.java

    Code:
    2011-11-27 19:40:23 [INFO] Starting minecraft server version Beta 1.8.1
    2011-11-27 19:40:23 [WARNING] **** NOT ENOUGH RAM!
    2011-11-27 19:40:23 [WARNING] To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
    2011-11-27 19:40:23 [INFO] Loading properties
    2011-11-27 19:40:23 [INFO] Starting Minecraft server on *:25565
    2011-11-27 19:40:23 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-1131-g86b7fa8-b1337jnks (MC: 1.8.1)
    2011-11-27 19:40:24 [INFO] Preparing level "world"
    2011-11-27 19:40:24 [INFO] Default game type: 0
    2011-11-27 19:40:24 [INFO] Preparing start region for level 0 (Seed: 5829037988444497796)
    2011-11-27 19:40:25 [INFO] Preparing spawn area: 48%
    2011-11-27 19:40:25 [INFO] Preparing start region for level 1 (Seed: 4316366300351042110)
    2011-11-27 19:40:26 [INFO] Preparing spawn area: 24%
    2011-11-27 19:40:27 [INFO] Preparing spawn area: 97%
    2011-11-27 19:40:27 [INFO] Done (0,346s)! For help, type "help" or "?"
    2011-11-27 19:40:34 [INFO] IDragonfire [/127.0.0.1:1400] logged in with entity id 82 at ([world] -369.2816919271674, 65.5, 347.8338077323248)
    2011-11-27 19:40:34 [WARNING] Task of 'PlayerMaxHealthDemo' generated an exception
    java.lang.NoSuchMethodError: org.bukkit.entity.Player.getMaxHealth()I
        at com.idragonfire.PlayerMaxHealthDemo$1.run(PlayerMaxHealthDemo.java:27)
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:137)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:441)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    2011-11-27 19:40:34 [WARNING] Task of 'PlayerMaxHealthDemo' generated an exception
    java.lang.NoSuchMethodError: org.bukkit.entity.Player.getMaxHealth()I
        at com.idragonfire.PlayerMaxHealthDemo$1.run(PlayerMaxHealthDemo.java:27)
        at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:137)
        at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:441)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
    2011-11-27 19:40:34 [INFO] New max size: 484
    2011-11-27 19:40:34 [INFO] New max size: 784
    2011-11-27 19:44:26 [INFO] CONSOLE: Stopping the server..
     
Thread Status:
Not open for further replies.

Share This Page