Type mismatch: cannot convert from Collection<capture#1-of ? extends Player> to Player[]

Discussion in 'Plugin Development' started by __Skyter__, Jan 6, 2016.

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

    __Skyter__

    Here crashes this error: Type mismatch: cannot convert from Collection<capture#1-of ? extends Player> to Player[]

    Code:
        public void reapDeadPlayers() {
            Player[] arrplayer = this.getServer().getOnlinePlayers(); // ERROR
            for (int i = 0; i < arrplayer.length; ++i) {
                Player player = arrplayer[i];
                String string = player.getName();
                if (!this.getDeadPlayerList().isPlayerDead(string, true)) continue;
                String string2 = this.getDeadPlayerList().whenWillPlayerLive(string).toString();
                player.kickPlayer("\ufffdcUmarles. Powstaniesz \ufffd4" + string2);
                this._thisPlugin.log("The reaper has caught up with " + string + " and taken them away.");
            }
     
  2. Offline

    Zombie_Striker

    @__Skyter__
    Well, it seems you're trying to convert a Array to a Collection. The way you have will not work.

    Instead, for loop through all the players in the Collection, and add each one individually to the array.
     
    ChipDev likes this.
  3. Offline

    ChipDev

    [] is a.. hmm.. I forgot what it is called, but it cannot be casted to something made externally, like a collection.
    This helped you 0%
     
  4. Offline

    Chloe-chan

    Instead of
    Code:
    Player[] arrplayer = this.getServer().getOnlinePlayers();
            for (int i = 0; i < arrplayer.length; ++i) {
                Player player = arrplayer[i];
    , use enhanced-for loop
    Code:
    for (Player player : getServer().getOnlinePlayers())
    {
     
Thread Status:
Not open for further replies.

Share This Page