简体   繁体   中英

Java Formatter issue

java.util.MissingFormatArgumentException: Format specifier 's'
    at java.util.Formatter.format(Formatter.java:2487) ~[na:1.7.0_80]
    at java.util.Formatter.format(Formatter.java:2423) ~[na:1.7.0_80]
    at java.lang.String.format(String.java:2enter code here792) ~[na:1.7.0_80]
    at com.aionemu.gameserver.utils.audit.GMService.onPlayerUnavailable(Unknown Source) ~[AL-Game.jar:na]
    at admincommands.GMMode.execute(GMMode.java]:73) ~[na:na]

while I was sending a command inside game, I am getting this error.

is that problem related with my config files or, completely with java ?

the entire code is :

package admincommands;

 import com.aionemu.gameserver.model.gameobjects.player.Player;
 import com.aionemu.gameserver.network.aion.serverpackets.SM_MOTION;
 import com.aionemu.gameserver.network.aion.serverpackets.SM_PLAYER_INFO;
 import com.aionemu.gameserver.utils.PacketSendUtility;
 import com.aionemu.gameserver.utils.audit.GMService;
 import com.aionemu.gameserver.utils.chathandlers.AdminCommand;

  */
 public class GMMode extends AdminCommand {

    public GMMode() {
        super("gm");
    }

    @Override
    public void execute(Player admin, String... params) {
        if (admin.getAccessLevel() < 1) {
            PacketSendUtility.sendMessage(admin, "You cannot use this command.");
            return;
        }

        if (params.length != 1) {
            onFail(admin, null);
            return;
        }

        if (params[0].toLowerCase().equals("on")) {
            if (!admin.isGmMode()) {
                admin.setGmMode(true);
                admin.setWispable();

                GMService.getInstance().onPlayerLogin(admin); // put gm into
                // gmlist
                GMService.getInstance().onPlayerAvailable(admin); // send
                // available
                // message
                admin.clearKnownlist();
                PacketSendUtility.sendPacket(admin, new SM_PLAYER_INFO(admin, false));
                PacketSendUtility.sendPacket(admin, new SM_MOTION(admin.getObjectId(), admin.getMotions().getActiveMotions()));
                admin.updateKnownlist();
                PacketSendUtility.sendMessage(admin, "you are now Available and Wispable by players");

            }
        }
        if (params[0].equals("off")) {
            if (admin.isGmMode()) {
                admin.setGmMode(false);
                admin.setUnWispable();

                GMService.getInstance().onPlayerLogedOut(admin); // remove gm
                // into
                // gmlist
                GMService.getInstance().onPlayerUnavailable(admin); // send
                // unavailable
                // message
                admin.clearKnownlist();
                PacketSendUtility.sendPacket(admin, new SM_PLAYER_INFO(admin, false));
                PacketSendUtility.sendPacket(admin, new SM_MOTION(admin.getObjectId(), admin.getMotions().getActiveMotions()));
                admin.updateKnownlist();
                PacketSendUtility.sendMessage(admin, "you are now Unavailable and Unwispable by players");
            }
        }
    }

    @Override
    public void onFail(Player admin, String message) {
        String syntax = "syntax //gm <on|off>";
        PacketSendUtility.sendMessage(admin, syntax);
    }
}

The exception tells you that there is a String.format taking place with more format specifiers than values for formatting. So somewhere there is a call like

ret = String.format("name %s, surname %s", "Firstname");

According to the stacktrace this happens in class com.aionemu.gameserver.utils.audit.GMService somewhere in method onPlayerUnavailable which is missing in your question.

A short Google-search brought up a Git-project where you can see the source of the culprit and there you can see a call of String.format :

Iterator<Player> iter = World.getInstance().getPlayersIterator();
while (iter.hasNext()) {
    PacketSendUtility.sendBrightYellowMessageOnCenter(iter.next(), "Information : " + String.format(adminTag, player.getName()) + LanguageHandler.translate(CustomMessageId.ANNOUNCE_GM_DECONNECTION));
}

The variable adminTag is built in dependence of settings in the instance of Player you're passing, so to say more we'd need information about the state of that instance- Looking at the source in general only shows the following lines to be a possible reason for the exception you encounter:

if (MembershipConfig.PREMIUM_TAG_DISPLAY) {
    switch (player.getClientConnection().getAccount().getMembership()) {
        case 1:
        adminTag = sb.insert(0, MembershipConfig.TAG_PREMIUM.substring(0, 2)).toString();
        break;
    case 2:
        adminTag = sb.insert(0, MembershipConfig.TAG_VIP.substring(0, 2)).toString();
        break;
    }
}
// * = Wedding
if (player.isMarried()) {
    adminTag = sb.insert(0, WeddingsConfig.TAG_WEDDING.substring(0, 2)).toString();
}

Looking at the corresponding classes that hold the values for eg TAG_WEDDING I guess that your configuration contains customized values for at least one of these constants that start with %s , so that adminTag ends up as %s%s .

So to answer your question

is that problem related with my config files or, completely with java ?

I guess that it's an error in your config file (some string starting with %s ) or a bug in the library you're using but it's definitely not a bug in Java.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM