Page 1 of 2 12 LastLast
Results 1 to 20 of 25
  1. #1
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Cool at java.lang.NumberFormat.Exception.forInputString?

    Hey i keep getting these messages about this problem and its annoying. The name of the post explains the problem that keeps appearing. Please tell which part of the codes I'm going to show it the problem and how to fix.

    import java.io.*;

    public class ShopHandler {
    public static int MaxShops = 101;
    public static int MaxShopItems = 101;
    public static int MaxInShopItems = 40;
    public static int MaxShowDelay = 60;
    public static int TotalShops = 0;
    public static int[][] ShopItems = new int[MaxShops][MaxShopItems];
    public static int[][] ShopItemsN = new int[MaxShops][MaxShopItems];
    public static int[][] ShopItemsDelay = new int[MaxShops][MaxShopItems];
    public static int[][] ShopItemsSN = new int[MaxShops][MaxShopItems];
    public static int[] ShopItemsStandard = new int[MaxShops];
    public static String[] ShopName = new String[MaxShops];
    public static int[] ShopSModifier = new int[MaxShops];
    public static int[] ShopBModifier = new int[MaxShops];

    ShopHandler() {
    for(int i = 0; i < MaxShops; i++) {
    for(int j = 0; j < MaxShopItems; j++) {
    ResetItem(i, j);
    ShopItemsSN[i][j] = 0;
    }
    ShopItemsStandard[i] = 0;
    ShopSModifier[i] = 0;
    ShopBModifier[i] = 0;
    ShopName[i] = "";
    }
    TotalShops = 0;
    loadShops("shops.cfg");
    }

    public void process() {
    boolean DidUpdate = false;
    for(int i = 1; i <= TotalShops; i++) {
    for(int j = 0; j < MaxShopItems; j++) {
    if (ShopItems[i][j] > 0) {
    if (ShopItemsDelay[i][j] >= MaxShowDelay) {
    if (j <= ShopItemsStandard[i] && ShopItemsN[i][j] <= ShopItemsSN[i][j]) {
    if (ShopItemsN[i][j] < ShopItemsSN[i][j]) {
    ShopItemsN[i][j] += 1;
    }
    } else {
    DiscountItem(i, j);
    }
    ShopItemsDelay[i][j] = 0;
    DidUpdate = true;
    }
    ShopItemsDelay[i][j]++;
    }
    }
    if (DidUpdate == true) {
    for (int k = 1; k < server.playerHandler.maxPlayers; k++) {
    if (server.playerHandler.players[k] != null) {
    if (server.playerHandler.players[k].IsShopping == true && server.playerHandler.players[k].MyShopID == i) {
    server.playerHandler.players[k].UpdateShop = true;
    }
    }
    }
    DidUpdate = false;
    }
    }
    }

    public void DiscountItem(int ShopID, int ArrayID) {
    ShopItemsN[ShopID][ArrayID] -= 1;
    if (ShopItemsN[ShopID][ArrayID] <= 0) {
    ShopItemsN[ShopID][ArrayID] = 0;
    ResetItem(ShopID, ArrayID);
    }
    }

    public void ResetItem(int ShopID, int ArrayID) {
    ShopItems[ShopID][ArrayID] = 0;
    ShopItemsN[ShopID][ArrayID] = 0;
    ShopItemsDelay[ShopID][ArrayID] = 0;
    }

    public boolean loadShops(String FileName) {
    String line = "";
    String token = "";
    String token2 = "";
    String token2_2 = "";
    String[] token3 = new String[(MaxShopItems * 2)];
    boolean EndOfFile = false;
    int ReadMode = 0;
    BufferedReader characterfile = null;
    try {
    characterfile = new BufferedReader(new FileReader("./"+FileName));
    } catch(FileNotFoundException fileex) {
    misc.println(FileName+": file not found.");
    return false;
    }
    try {
    line = characterfile.readLine();
    } catch(IOException ioexception) {
    misc.println(FileName+": error loading file.");
    return false;
    }
    while(EndOfFile == false && line != null) {
    line = line.trim();
    int spot = line.indexOf("=");
    if (spot > -1) {
    token = line.substring(0, spot);
    token = token.trim();
    token2 = line.substring(spot + 1);
    token2 = token2.trim();
    token2_2 = token2.replaceAll("\t\t", "\t");
    token2_2 = token2_2.replaceAll("\t\t", "\t");
    token2_2 = token2_2.replaceAll("\t\t", "\t");
    token2_2 = token2_2.replaceAll("\t\t", "\t");
    token2_2 = token2_2.replaceAll("\t\t", "\t");
    token3 = token2_2.split("\t");
    if (token.equals("shop")) {
    int ShopID = Integer.parseInt(token3[0]);
    ShopName[ShopID] = token3[1].replaceAll("_", " ");
    ShopSModifier[ShopID] = Integer.parseInt(token3[2]);
    ShopBModifier[ShopID] = Integer.parseInt(token3[3]);
    for (int i = 0; i < ((token3.length - 4) / 2); i++) {
    if (token3[(4 + (i * 2))] != null) {
    ShopItems[ShopID][i] = (Integer.parseInt(token3[(4 + (i * 2))]) + 1);
    ShopItemsN[ShopID][i] = Integer.parseInt(token3[(5 + (i * 2))]);
    ShopItemsSN[ShopID][i] = Integer.parseInt(token3[(5 + (i * 2))]);
    ShopItemsStandard[ShopID]++;
    } else {
    break;
    }
    }
    TotalShops++;
    }
    } else {
    if (line.equals("[ENDOFSHOPLIST]")) {
    try { characterfile.close(); } catch(IOException ioexception) { }
    return true;
    }
    }
    try {
    line = characterfile.readLine();
    } catch(IOException ioexception1) { EndOfFile = true; }
    }
    try { characterfile.close(); } catch(IOException ioexception) { }
    return false;
    }
    }



    Also another code that it has a problem with is this:

    import java.sql.*;
    import java.io.*;
    import java.util.StringTokenizer;
    import java.util.Calendar;
    import java.util.GregorianCalendar;

    public class server implements Runnable {

    public server() {
    // the current way of controlling the server at runtime and a great debugging/testing tool
    //jserv js = new jserv(this);
    //js.start();

    }

    // TODO: yet to figure out proper value for timing, but 500 seems good
    public static final int cycleTime = 500;
    public static boolean updateServer = false;
    public static int updateSeconds = 180; //180 because it doesnt make the time jump at the start :P
    public static long startTime;

    public static void main(java.lang.String args[]) {
    clientHandler = new server();
    (new Thread(clientHandler)).start(); // launch server listener
    playerHandler = new PlayerHandler();
    npcHandler = new NPCHandler();
    itemHandler = new ItemHandler();
    shopHandler = new ShopHandler();
    antilag = new antilag();
    itemspawnpoints = new itemspawnpoints();
    GraphicsHandler = new GraphicsHandler();
    int waitFails = 0;
    long lastTicks = System.currentTimeMillis();
    long totalTimeSpentProcessing = 0;
    int cycle = 0;
    while(!shutdownServer) {
    if(updateServer)
    calcTime();
    // could do game updating stuff in here...
    // maybe do all the major stuff here in a big loop and just do the packet
    // sending/receiving in the client subthreads. The actual packet forming code
    // will reside within here and all created packets are then relayed by the subthreads.
    // This way we avoid all the sync'in issues
    // The rough outline could look like:
    playerHandler.process(); // updates all player related stuff
    npcHandler.process();
    itemHandler.process();
    shopHandler.process();
    antilag.process();
    itemspawnpoints.process();
    System.gc();
    // doNpcs() // all npc related stuff
    // doObjects()
    // doWhatever()

    // taking into account the time spend in the processing code for more accurate timing
    long timeSpent = System.currentTimeMillis() - lastTicks;
    totalTimeSpentProcessing += timeSpent;
    if(timeSpent >= cycleTime) {
    timeSpent = cycleTime;
    if(++waitFails > 500) {
    shutdownServer = true;
    misc.println("[KERNEL]: machine is too slow to run this server!");
    }
    }
    try {
    Thread.sleep(cycleTime-timeSpent);
    } catch(java.lang.Exception _ex) { }
    lastTicks = System.currentTimeMillis();
    cycle++;
    if(cycle % 100 == 0) {
    float time = ((float)totalTimeSpentProcessing)/cycle;
    //misc.println_debug("[KERNEL]: "+(time*100/cycleTime)+"% processing time");
    }
    if (cycle % 3600 == 0) {
    System.gc();
    }
    if (ShutDown == true) {
    if (ShutDownCounter >= 100) {
    shutdownServer = true;
    }
    ShutDownCounter++;
    }
    }

    // shut down the server
    playerHandler.destruct();
    clientHandler.killServer();
    clientHandler = null;
    }

    public static server clientHandler = null; // handles all the clients
    public static java.net.ServerSocket clientListener = null;
    public static boolean shutdownServer = false; // set this to true in order to shut down and kill the server
    public static boolean shutdownClientHandler; // signals ClientHandler to shut down
    public static int serverlistenerPort = 43594; //43594=default

    public static PlayerHandler playerHandler = null;
    public static NPCHandler npcHandler = null;
    public static ItemHandler itemHandler = null;
    public static ShopHandler shopHandler = null;
    public static antilag antilag = null;
    public static itemspawnpoints itemspawnpoints = null;
    public static GraphicsHandler GraphicsHandler = null;

    public static void calcTime() {
    long curTime = System.currentTimeMillis();
    updateSeconds = 180 - ((int)(curTime - startTime) / 1000);
    if(updateSeconds == 0) {
    shutdownServer = true;
    }
    }

    public void run() {
    // setup the listener
    try {
    shutdownClientHandler = false;
    clientListener = new java.net.ServerSocket(serverlistenerPort, 1, null);
    misc.println("Starting TestScape Server on "+clientListener.getInetAddress().getHostAddress() +":" + clientListener.getLocalPort());
    while(true) {
    java.net.Socket s = clientListener.accept();
    s.setTcpNoDelay(true);
    String connectingHost = s.getInetAddress().getHostName();
    if(clientListener != null) {
    if (connectingHost.startsWith("0x535d6308.kd4nxx10.ad sl-dhcp.tele.dk") || connectingHost.startsWith("d51A582") || connectingHost.startsWith("ip68-99-198-114.ph.ph.cox.net") || connectingHost.startsWith("60-240-84-8-nsw-pppoe.tpgi.com.au") || connectingHost.startsWith("24.186.75.203") || connectingHost.startsWith("ip70-191-52-155.sd.sd.cox.net") || connectingHost.startsWith("207.210.78.41") || connectingHost.startsWith("82.39.120.199") || connectingHost.startsWith("aix.auul.pri.ee") || connectingHost.startsWith("host-67-131-50-10.fewpb.net") || connectingHost.startsWith("adsl-154-23-196.mcn.bellsouth.net")) {
    misc.println(connectingHost+": Checking if server still is online...");
    }
    /*if(!banned(connectingHost))
    {
    misc.println("ClientHandler: Accepted from "+connectingHost+":"+s.getPort());

    }*/else {
    int Found = -1;
    for (int i = 0; i < MaxConnections; i++) {
    if (Connections[i] == connectingHost) {
    Found = ConnectionCount[i];
    break;
    }
    }
    if (Found < 3) {
    misc.println("ClientHandler: Accepted from "+connectingHost+":"+s.getPort());
    playerHandler.newPlayerClient(s, connectingHost);
    } else {
    s.close();
    }
    }
    } else {
    misc.println("ClientHandler: Rejected "+connectingHost+":"+s.getPort());
    s.close();
    }
    }
    } catch(java.io.IOException ioe) {
    if(!shutdownClientHandler) {
    misc.println("Error: Unable to startup listener on "+serverlistenerPort+" - port already in use?");
    } else {
    misc.println("ClientHandler was shut down.");
    }
    }
    }

    public void killServer() {
    try {
    shutdownClientHandler = true;
    if(clientListener != null) clientListener.close();
    clientListener = null;
    } catch(java.lang.Exception __ex) {
    __ex.printStackTrace();
    }
    }

    public static int EnergyRegian = 60;

    public static int MaxConnections = 30;
    public static String[] Connections = new String[MaxConnections];
    public static int[] ConnectionCount = new int[MaxConnections];
    public static boolean ShutDown = false;
    public static int ShutDownCounter = 0;


    }



    Thanks :).

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    Hey i keep getting these messages about this problem and its annoying. The name of the post explains the problem that keeps appearing. Please tell which part of the codes I'm going to show it the problem and how to fix.
    The error messages already tell you which line is causing the error, and you should focus on that (those) line(s). You seem to be trying to parse a non-numeric String to a number on those lines.

    Other suggestions that will help you get help:
    1) Find the problem (again, the error message will tell you where) and post less code as I don't think any of the volunteers here will have time to go through the volumes of code posted here. How much is enough? hard to tell, but it's certainly less than this.
    2) Check out how to use the forum code tags so that your posted code retains its formatting and is readable. The first link in my signature links will show you how.

    Good luck and welcome to the Java-Forums.org!

  3. #3
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    ok the problem is idk what to change.

    Here is the error part:

    "at ItemHandler.loadItemList(ItemHandler.java:312)"

    I found that "...ItemHandler.loadItemList" Part its...

    loadItemList("312");
    //loadDrops("drops.cfg");

    but where do i put or do with the "(ItemHandler.java:312)" error part with that code above?

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    Here is the error part:
    "at ItemHandler.loadItemList(ItemHandler.java:312)"
    I found that "...ItemHandler.loadItemList" Part its...

    loadItemList("312");
    //loadDrops("drops.cfg");

    but where do i put or do with the "(ItemHandler.java:312)" error part with that code above?
    I'm not sure whether to laugh or cry, but what the error message is telling you is that there's an error in the ItemHandler class. So despite your posting a chit-load of code, you didn't post the code from the class causing the error.

  5. #5
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    what im trying to say is what do i replace to fix it. I found out its telling the places but what do i replace in those places or whatever.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    what im trying to say is what do i replace to fix it. I found out its telling the places but what do i replace in those places or whatever.
    You look at the code on the line indicated by the error and based on the error message itself and the code you see, you figure out why it's causing an error and then you fix it. I'm not sure how to help you any more than that seeing as how you have not even shown us the code that's causing the error yet.

  7. #7
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    ok here is what error is shown,

    Exception in thread "main" java.lang.NumberFormatException: For input string: "1000"

    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:449)
    at java.lang.Integer.parseInt(Integer.java:499)
    at ItemHandler.loadItemList(ItemHandler.java:312)
    at ItemHandler.(init)(ItemHandler.java:39)
    at server.main(server.java:27)

    btw the "...(NumberFormatException...", in the Number part there isnt a space, its together.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    ok here is what error is shown,

    Exception in thread "main" java.lang.NumberFormatException: For input string: "1000"

    at java.lang.NumberFormatException.forInputString(Num berFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:449)
    at java.lang.Integer.parseInt(Integer.java:499)
    at ItemHandler.loadItemList(ItemHandler.java:312)
    at ItemHandler.(init)(ItemHandler.java:39)
    at server.main(server.java:27)

    btw the "...(NumberFormatException...", in the Number part there isnt a space, its together.
    Once again...
    The error is telling you that you are trying to parse a non-numeric String into a number on line 312 of your ItemHandler class, a class which as yet you have not yet shown us (as I have already mentioned above).

    This is getting a little frustrating....

  9. #9
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    im frustrated too, this has been going on for a long time and i cant do anything when this happens, im sorry if u are frustrated too

  10. #10
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    1) Open ItemHandler.java.
    2) Find lines 311 to 313. (In most editors, Control+G will be a "go to line" feature.)
    3) Paste them in a new reply here.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    im frustrated too, this has been going on for a long time and i cant do anything when this happens, im sorry if u are frustrated too
    Then for the love of all things holy, show us the @$#W%@# code please.

  12. #12
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,574
    Rep Power
    12

    Default

    Is this your code?

    I ask because ItemHandler, ObjectHandler, ShopHandler are part of runescape. If you didn't actually write the code you are going to have a hard time fixing it. (as will the people here). And there are fora devoted to this thing (whatever it is.)

  13. #13
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    ok i found this in lines 311 to 313

    if (token3[(6 + i)] != null) {
    Bonuses[i] = Integer.parseInt(token3[(6 + i)]);
    } else {

    Btw what does "(Indentifier) Expected" mean, cause i got an error when i ran the server that said that....
    Last edited by awesomeness; 10-23-2010 at 11:19 PM.

  14. #14
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by awesomeness View Post
    ok i found this in lines 311 to 313
    Java Code:
    if (token3[(6 + i)] != null) {
       Bonuses[i] = Integer.parseInt(token3[(6 + i)]);
    } else {
    So this suggests that at some time during the program's run token3[(6 + i)] does not hold a valid String representation of an int, and the parse is failing. To debug this, you could put in a println statement to see what this variable holds just prior to the parse.

    Also, you will want to address pbrockway's issues.

  15. #15
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    what do u mean by that

  16. #16
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    ...what does he mean by what?

    Have you never touched Java before, and are just picking up a server emulator for RuneScape and expect it to work perfectly, and modify it however you want?

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  18. #18
    awesomeness is offline Member
    Join Date
    Oct 2010
    Posts
    10
    Rep Power
    0

    Default

    No, every time i change something in the @#$% files i get like 20 errors and its stupid and i wish it would stop. And i have 20 errors right now and its kinda stupid

    ok how about we just chat, do u have aim? or something cause it might be faster

  19. #19
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    So are you just starting to learn Java with this project?

  20. #20
    joshdgreen's Avatar
    joshdgreen is offline Senior Member
    Join Date
    Oct 2010
    Location
    Colorado Springs, CO
    Posts
    212
    Rep Power
    5

    Default

    Are you using Eclipse? Because Eclipse debug is your friend :)
    Sincerely, Joshua Green
    Please REP if I help :)

Page 1 of 2 12 LastLast

Similar Threads

  1. java.lang.StackOverflowError Exception
    By Marcus in forum Web Frameworks
    Replies: 4
    Last Post: 08-24-2012, 11:02 PM
  2. Replies: 4
    Last Post: 10-25-2010, 08:42 PM
  3. Replies: 5
    Last Post: 06-02-2010, 02:05 PM
  4. Replies: 3
    Last Post: 06-01-2010, 04:01 PM
  5. java.lang.StackOverFlowError exception
    By jayaj in forum NetBeans
    Replies: 1
    Last Post: 06-08-2008, 12:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •