Results 1 to 2 of 2

Thread: string out of bounds error

  1. #1
    Chillie in here j.o.s.h.1408's Avatar
    Join Date
    Dec 2005
    Location
    a place called home
    Posts
    8,543
    Thanks
    757
    Thanked
    256 times in 193 posts
    • j.o.s.h.1408's system
      • Motherboard:
      • ASUS P6T Delux
      • CPU:
      • Intel core i7 920 @ 3ghz
      • Memory:
      • 3GB DDR RAM
      • Storage:
      • 1TB Samsung F1, 500GB Seagate baracuda + 320gb Seagate PATA +150GB WD PATA
      • Graphics card(s):
      • EVGA 480GTX SC edition
      • PSU:
      • Seasonic M12 600W Module PSU FTW
      • Case:
      • Lian Li PC-A7010B (the rolls royce of pc cases)
      • Operating System:
      • vista ultimate edition and windows xp
      • Monitor(s):
      • 22inch 2005FPW dell monitor
      • Internet:
      • 24mb BE There Broadband

    string out of bounds error

    Hi i am getting a very strange exception that i dont quit understand because when i debug the area in which the exception is thrown, no exception is thrown during debugging at the specific area.

    to make my problem simplier to understand, the exception points to this code below that gets some string value and splits into an array and than grab a part of the string value.

    Code:
    public String split(String original, String separator)
         {
             Vector nodes = new Vector();
             String tab = "";
    
            // Parse nodes into vector
            int index = original.indexOf(separator);
            while(index>=0) 
            {
                nodes.addElement( original.substring(0, index) );
                original = original.substring(index+separator.length());
                index = original.indexOf(separator);
            }
            // Get the last node
            nodes.addElement( original );
    
            // Create splitted string array
            String[] result = new String[ nodes.size() ];
            if( nodes.size()>0 ) 
            {
                for(int loop=0; loop<nodes.size(); loop++)
                result[loop] = (String)nodes.elementAt(loop);
            }
            ///////////////////////////////
            
            StringBuffer b = new StringBuffer();
            int length = 0;
            int j = 0;
            try
            {
                    int g = 0;
                    int q = 0;
                    
                        length = result[2].length();
                        
    
                        while(q < length)
                        {
                            char val = result[2].charAt(q);
                            if ((val == '"') && (g == 0) && (length != q))
                            {
    
                                //store digits
                                g = q;
                                char val1;
                                while((val1 = result[2].charAt(g+1)) != '"')  // exception error points here
                                {
                                    b.append(val1);
                                    g++;
                                }
    
                            }
                            q++;
                        }
                      g=0;
                      q=0;
                    
                    
                    tab = b.toString();
            
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            
            
            return tab;
         }
    The following code is executed below in this method. look at the amount of times the method split() is executed. when debugging it, not one of them indicates an exception but has soon as i move to the next part of my code, the exception is thrown.


    Code:
    //get the values and prepare them
                 fname = "?sg_FirstName=" + split(data[8], " ") + "\n" + "\0";
                 lname = "&sg_LastName=" + split(data[9], " ") + "\n" + "\0";
                 address = "&sg_Address=" + split(data[10], " ") + "\n" + "\0";
                 city = "&sg_City=" + split(data[18], " ") + "\n" + "\0";
                 state1 = "&sg_State=" + "&" + "\n" + "\0";
                 ip = "sg_IPAddress=&" + "\n" + "\0";
                 zip = "sg_Zip=" + split(data[12], " ") + "\n" + "\0";
                 country = "&sg_Country=" + split(data[16], " ") + "\n" + "\0";
                 phone = "&sg_Phone=" + split(data[13], " ") + "\n" + "\0";
                 email = "&sg_Email=" + split(data[11], " ")+ "\n" + "\0";
                 cvv2 = "&sg_CVV2=" + card[0] + "\n" + "\0";
                 number = "&sg_CardNumber=" + card[1] + "\n" + "\0";
                 expM = "&sg_ExpMonth=" + card[2] + "\n" + "\0";
                 expY = "&sg_ExpYear=" + card[3] + "\n" + "\0";
                 amount = "&sg_Amount=" + card[4] + "\n" + "\0";
                 id = "&sg_ClientUniqueID=" + split(data[6], " ") + "\n" + "\0";
                 login = "&login=" + split(data[0], " ") + "\n" + "\0";
                 pass = "&pass=" + split(data[1], " ") + "\n" + "\0";
                 lang = "&lang=" + split(data[2], " ") + "\n" + "\0";
                 cur = "&cur=" + split(data[19], " ") + "\n" + "\0";
                 String sid = "id=1&" + "\n" + "\0";
                 String cart = "cartec=casino770" + "\n" + "\0";
                 
    //exception thrown at this point but why?
                 String url2 = "http://fcg.casino770.com/fcg-games/depot/mobileok.php3"
                         +fname+lname+address+city+state1+ip+zip+country+phone
                         +email+cvv2+number+expM+expY+amount+id+login+pass+lang
                         +cur+sid+cart;
     
                 
                 server2 = (HttpConnection) Connector.open(url2, Connector.READ_WRITE);
    Please note that the type of data thats contained in result[2] is value="glazlo">

    Thanks for reading this and hope someone can help me thanks

  2. #2
    Seething Cauldron of Hatred TheAnimus's Avatar
    Join Date
    Aug 2005
    Posts
    17,164
    Thanks
    803
    Thanked
    2,152 times in 1,408 posts
    only reading a very little of your post.

    http://java.sun.com/j2se/1.4.2/docs/...tml#charAt(int)

    surely thats where the problem is as that you say is where the exception is?

    basically you've got a while look, and your 'escape condition' is when you don't get a ", but you might actually finish the string first!

    ie. add ((g+1) <= result[2].Length) &&

    make sure you do this before you evaluate the .CharAt, otherwise remove the =.
    throw new ArgumentException (String, String, Exception)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. j2me out of memory error
    By j.o.s.h.1408 in forum Software
    Replies: 3
    Last Post: 25-04-2007, 12:11 AM
  2. graphics card error
    By amit12345 in forum PC Hardware and Components
    Replies: 0
    Last Post: 09-04-2007, 03:43 PM
  3. Did my OC cause this?
    By myth in forum PC Hardware and Components
    Replies: 19
    Last Post: 05-04-2005, 12:36 PM
  4. Zakky - Thanks for the string dude :)
    By Tumble in forum General Discussion
    Replies: 3
    Last Post: 03-06-2004, 03:01 PM
  5. 8o!! taste hot WineX powaaah!
    By directhex in forum Software
    Replies: 33
    Last Post: 31-05-2004, 08:18 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
  •