Solved java.lang.NumberFormatException: For input string: "w"

Discussion in 'Plugin Development' started by soulofw0lf, Jul 25, 2013.

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

    soulofw0lf

    @xTrollxDudex - show me the simplistic thing my tiredness is missing :)
    I can only assume in this instance that my lack of sleep is hampering my ability to see what is obviously a simple fix.... https://gist.github.com/soulofwolf/b6ca1e93e880d64f9945 it should be noted that the line 45 referenced is line 12 on the gist, the line it shouldn't be even getting to... and the Vector Blocks: segment is the part of the vecConfig that it is grabbing the location from. Any assistance here is greatly appreciated
     
  2. Offline

    PogoStick29

    Please format your post. As far as your code, please don't put a jumble of different lines in one file. However, it looks fine on first glance.
     
  3. Offline

    soulofw0lf

    actually PogoStick29 if more people were to line up their code with their errors and show all relevant lines and what they pertain to it would be alot easier to help people out. It's not a "jumble of lines" it's code clearly seperated and below the error lines that references it to make it easier for people that don't have the full source to have an idea of what's going on.
     
  4. Offline

    PogoStick29

    Fair enough.
     
  5. Offline

    Tirelessly

    Actually if you only post certain lines then I have to trust that you know what's causing the issue, which I don't.
     
    PogoStick29 likes this.
  6. Offline

    soulofw0lf

    Well i suppose i should apologise for making assumptions about how easy it should be to read that file, i will explain it line by lin in an effort to hopefully get some input on the problem itself.

    This line indicates that the error occured during onEnable method when the loaders are called for the plugin

    Code:
    /2013-07-25 19:21:23 [SEVERE] Error occurred while enabling RpgAPI v0.2 (Is it up to date?)
    
    This line is stating that w is not in fact a number. It surprised me too

    Code:
    //java.lang.NumberFormatException: For input string: "w"
    This next line is showing us where the NumberFormatException occured on line 45 of the Misc class, line 45 being the last line in the stringToLoc method

    Code:
    //at com.vartala.soulofw0lf.rpgapi.util.Misc.stringToLoc(Misc.java:45)
    This is the stringToLoc Method if you look closely here you will notice that if the length of arr is equal to 4 this method should not get to the end line that is erroring

    Code:
    public static Location stringToLoc(String s) {
    String[] arr = s.split("|");
    if (arr.length == 4)
    return new Location(Bukkit.getWorld(arr[0]), Double.parseDouble(arr[1]), Double.parseDouble(arr[2]), Double.parseDouble(arr[3]));
    else
    return new Location(Bukkit.getWorld(arr[0]), Double.parseDouble(arr[1]), Double.parseDouble(arr[2]), Double.parseDouble(arr[3]), Float.parseFloat(arr[4]), Float.parseFloat(arr[5]));
    

    Here we have another line of the error message showing the string being sent was from line 71 of the VectorLoader class

    Code:
    //at com.vartala.soulofw0lf.rpgapi.loaders.VectorLoader.<init>(VectorLoader.java:71)
    Line 71 is provided here showing where the string is being pulled from. Since it may be hard to realise vecConfig is a YamlConfiguration

    Code:
    Location loc = Misc.stringToLoc(vecConfig.getString("Vector Blocks." + key + ".Location"));
    Here we have the specific part of the YamlConfiguration that's referenced above now if you look closely at the stringToLoc method it seperates the string at | which would make the string gotten from the location here 4 argumentsm meaning it shouldn't be passing onto the last line of the method where it is erroring

    Code:
    Vector Blocks:
    '1':
    Location: 'world|0|0|0'
    Vector: '-0.8|1.6|-2.0'
    Vector Immune: '40'
    
    This line was included because i copied on line too low and didn't notice it when i pasted. it's relevance has yet to be decided,


    Code:
    //at com.vartala.soulofw0lf.rpgapi.RpgAPI.onEnable(RpgAPI.java:336)
    I hope this can assist you in helping me figure out exactly what is going crazy here. thank you.
     
  7. Offline

    Tirelessly

    I guess you didn't understand me.
     
  8. Offline

    soulofw0lf

    If your intent was to in anyway be helpful then no i apologize i did not understand you. If you would instead prefer to go over the 50-ish thousand lines of code in this plugin to try to look for the error in a place it doesn't exist i'd be happy to link you to my github.

    @chasechocolate @xTrollxDudex any thoughts on this one at all?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  9. Offline

    xTrollxDudex

    soulofw0lf
    What did you do to recieve the error? What exactly was executed and what was the intent of it?
     
  10. Offline

    soulofw0lf

    that's just loading the RpgVectorBlock objects onEnable from yml to save them to a list.

    here's the full loader for ya also has the command handling in the class for that one

    Code:java
    1. public class VectorLoader {
    2. RpgAPI rpg;
    3. public VectorLoader(RpgAPI Rpg){
    4. this.rpg = Rpg;
    5.  
    6. new VecBlockListener(this.rpg);
    7. YamlConfiguration vecConfig = YamlConfiguration.loadConfiguration(new File("plugins/RpgVectorBlocks/config.yml"));
    8. if (vecConfig.get("Vector Blocks") == null){
    9. vecConfig.set("Vector Command", "vec");
    10. vecConfig.set("Vector Message", "&f[&2Rpg Vector Blocks&f] &eVector @n Created!");
    11. vecConfig.set("Vector Exists", "&f[&2Rpg Vector Blocks&f] &eA vector named [USER=44453]N A[/USER]lready exists!");
    12. vecConfig.set("Vector Permission", "vector.make");
    13. vecConfig.set("Vector Permission Denied", "&f[&2Rpg Vector Blocks&f] &4You do not have permission to set new vectors!");
    14. vecConfig.set("Vector Error", "&f[&2Rpg Vector Blocks&f] &4Error please use /vec name immunetime vecx vecy vecz");
    15. vecConfig.set("Vector Blocks.1.Location", "world|0|0|0");
    16. vecConfig.set("Vector Blocks.1.Vector", "-.8|1.6|-2.0");
    17. vecConfig.set("Vector Blocks.1.Vector Immune", "40");
    18. try {
    19. vecConfig.save(new File("plugins/RpgVectorBlocks/config.yml"));
    20. } catch (IOException e){
    21. e.printStackTrace();
    22. }
    23. }
    24. RpgAPI.commands.add(vecConfig.getString("Vector Command"));
    25. RpgAPI.commandSettings.put("Vector Command", vecConfig.getString("Vector Command"));
    26. RpgAPI.localeSettings.put("Vector Message", vecConfig.getString("Vector Message"));
    27. RpgAPI.localeSettings.put("Vector Exists", vecConfig.getString("Vector Exists"));
    28. RpgAPI.localeSettings.put("Vector Permission Denied", vecConfig.getString("Vector Permission Denied"));
    29. RpgAPI.localeSettings.put("Vector Error", vecConfig.getString("Vector Error"));
    30. RpgAPI.permissionSettings.put("Vector Permission", vecConfig.getString("Vector Permission"));
    31. for (String key : vecConfig.getConfigurationSection("Vector Blocks").getKeys(false)){
    32. if (key == null){
    33. continue;
    34. }
    35. Location loc = Misc.stringToLoc(vecConfig.getString("Vector Blocks." + key + ".Location"));
    36. Block b = loc.getBlock();
    37. RpgVectorBlocks rV = new RpgVectorBlocks(key, b, vecConfig.getInt("Vector Blocks." + key + ".Vector Immune"), Misc.stringToVec(vecConfig.getString("Vector Blocks." + key + ".Vector")));
    38. RpgAPI.vecBlocks.add(b);
    39. RpgAPI.vecBlockMap.put(b, rV);
    40. }
    41. }
    42. public static boolean vectorCommands(String[] cmd, Player p){
    43. if (cmd[0].equalsIgnoreCase(RpgAPI.commandSettings.get("Vector Command"))){
    44. RpgPlayer rp = RpgAPI.getRp(p);
    45. if (!rp.hasPermission(RpgAPI.permissionSettings.get("Vector Permission"))){
    46. p.sendMessage(ChatColors.ChatString(RpgAPI.localeSettings.get("Vector Permission Denied")));
    47. return true;
    48. }
    49. if (cmd.length != 6){
    50. p.sendMessage(ChatColors.ChatString(RpgAPI.localeSettings.get("Vector Error")));
    51. return true;
    52. }
    53. for (Block b : RpgAPI.vecBlocks){
    54. RpgVectorBlocks rv = RpgAPI.vecBlockMap.get(b);
    55. if (rv.getName().equalsIgnoreCase(cmd[1])){
    56. p.sendMessage(ChatColors.ChatString(RpgAPI.localeSettings.get("Vector Exists").replace("@n", cmd[1])));
    57. return true;
    58. }
    59. }
    60. Block bl = p.getLocation().getBlock().getRelative(BlockFace.DOWN);
    61. RpgVectorBlocks rVb = new RpgVectorBlocks(cmd[1], bl, Integer.parseInt(cmd[2]), new Vector(Double.parseDouble(cmd[3]), Double.parseDouble(cmd[4]), Double.parseDouble(cmd[5])));
    62. RpgAPI.vecBlocks.add(bl);
    63. RpgAPI.vecBlockMap.put(bl, rVb);
    64. p.sendMessage(ChatColors.ChatString(RpgAPI.localeSettings.get("Vector Message").replace("@n", rVb.getName())));
    65. return true;
    66. }
    67.  
    68. return false;
    69. }
    70. }
    71.  


    @xTrollxDudex forgot to tag. also the weird thing... it's still running the vectorblocks in game as intended, just won't actually save to the yml file afterwards since it errors out on loading it due to the type mismatch.

    @xTrollxDudex forgot to tag. also the weird thing... it's still running the vectorblocks in game as intended, just won't actually save to the yml file afterwards since it errors out on loading it due to the type mismatch.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  11. Offline

    xTrollxDudex

    soulofw0lf
    What executed to cause the error? What happened to cause the error?
     
  12. Offline

    soulofw0lf

    xTrollxDudex it's erroring onEnable while loading the string from config to a location through the stringToLoc method, what's confusing me the most is it's getting to the end of the method when it's length is 4 so it shouldn't even get ot that part.
     
  13. Offline

    xTrollxDudex

  14. Offline

    soulofw0lf

    Here are all relevant parts of my github if you want to see any more of the srouce for this.
    1. https://github.com/soulofw0lf/RpgAP...a/soulofw0lf/rpgapi/loaders/VectorLoader.java
    2. https://github.com/soulofw0lf/RpgAPI/tree/master/src/com/vartala/soulofw0lf/rpgapi/vectorapi
    3. https://github.com/soulofw0lf/RpgAPI/blob/master/src/com/vartala/soulofw0lf/rpgapi/util/Misc.java
    4. https://github.com/soulofw0lf/RpgAP...artala/soulofw0lf/rpgapi/savers/VecSaver.java

    @xTrollxDudex the Class called during onEnable is the vector loader, firt one there

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  15. Offline

    xTrollxDudex

    soulofw0lf
    You can fix the onEnable by closing the constructor in Vector Loader
     
  16. Offline

    soulofw0lf

    @xTrollxDudex while i wish it could be that simple the loading was actually intended to be part of the constructor, nevertheless tried it out just incase and set everything else in a seperate method, exact same error.
    https://github.com/soulofw0lf/RpgAP...a/soulofw0lf/rpgapi/loaders/VectorLoader.java

    Code:
    2013-07-26 00:34:14 [SEVERE] Error occurred while enabling RpgAPI v0.2 (Is it up to date?)
    java.lang.NumberFormatException: For input string: "w"
        at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1241)
        at java.lang.Double.parseDouble(Double.java:540)
        at com.vartala.soulofw0lf.rpgapi.util.Misc.stringToLoc(Misc.java:45)
        at com.vartala.soulofw0lf.rpgapi.loaders.VectorLoader.loader(VectorLoader.java:75)
        at com.vartala.soulofw0lf.rpgapi.loaders.VectorLoader.<init>(VectorLoader.java:43)
        at com.vartala.soulofw0lf.rpgapi.RpgAPI.onEnable(RpgAPI.java:336)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:217)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:457)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.loadPlugin(CraftServer.java:282)
        at org.bukkit.craftbukkit.v1_6_R2.CraftServer.enablePlugins(CraftServer.java:264)
        at net.minecraft.server.v1_6_R2.MinecraftServer.l(MinecraftServer.java:313)
        at net.minecraft.server.v1_6_R2.MinecraftServer.f(MinecraftServer.java:290)
        at net.minecraft.server.v1_6_R2.MinecraftServer.a(MinecraftServer.java:250)
        at net.minecraft.server.v1_6_R2.DedicatedServer.init(DedicatedServer.java:151)
        at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:391)
        at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
     
  17. Offline

    xTrollxDudex

    soulofw0lf
    A temporary fix is to take the world/coordinates separately, try outputting the result of splitting the location, maybe that will reveal something
     
  18. Offline

    soulofw0lf

    ok yeah good call it's splitting every single letter. i can't believe i didn't test that hours ago
    Code:
    w
    11:47:08 PM CONSOLE: [INFO] o
    11:47:08 PM CONSOLE: [INFO] r
    11:47:08 PM CONSOLE: [INFO] l
    11:47:08 PM CONSOLE: [INFO] d
    11:47:08 PM CONSOLE: [INFO] |
    11:47:08 PM CONSOLE: [INFO] 0
    11:47:08 PM CONSOLE: [INFO] .
    11:47:08 PM CONSOLE: [INFO] 0
    11:47:08 PM CONSOLE: [INFO] |
    11:47:08 PM CONSOLE: [INFO] 0
    11:47:08 PM CONSOLE: [INFO] .
    11:47:08 PM CONSOLE: [INFO] 0
    11:47:08 PM CONSOLE: [INFO] |
    11:47:08 PM CONSOLE: [INFO] 0
    11:47:08 PM CONSOLE: [INFO] .
    11:47:08 PM CONSOLE: [INFO] 0
    @xTrollxDudex and fixed man thank you sooo much for the help!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 3, 2016
  19. Offline

    xTrollxDudex

    soulofw0lf
    Awesome, but I really didn't help that much.
     
Thread Status:
Not open for further replies.

Share This Page