Results 1 to 4 of 4
  1. #1
    boys21 is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default string to integer conversion

    hi,

    i am working with excel and java. by default, value extracted from a cell of excel sheet is string. In a column i have 3000 numerical values. As excel sheet cell is returning string, i created a string array to store column elements. when i try to convert those string values to integer,

    1.It is throwing an exception of array index out of bounds? why?

    2. also, when i tried to print the string values directly, it is throwing exception in middle of values, but still i could see all values? but, with exception message.

    please help me, thanks in advance.

    br,
    boys21

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,963
    Rep Power
    8

    Default Re: string to integer conversion

    If you want help, you'll have to provide an SSCCE that demonstrates the problem. Otherwise, we have no idea what you're doing.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    boys21 is offline Member
    Join Date
    May 2010
    Posts
    14
    Rep Power
    0

    Default Re: string to integer conversion

    ok..
    assume my excel sheet have 1000 rows, 5 columns
    iam extracing data from excel sheet cells and trying to make statistical analysis and modifications on excel data through arrays,

    //create a work book to access data.

    //created a multi dimensional array of string datatype to save the data into cells

    string [][] x;
    x=new string [column][row];

    TO copy contents from a cells to array; i used nested for loops

    for loop(column){

    for loop (row)
    {
    x[i][j]=cell.getcontents(column,row);
    }
    }

    NOw, i hold all cells data of excel sheet in a multi dimensional array.

    assume i want to manuplate, 2nd column elements to make some analysis.

    excel Cell return string type , so i used string array to store. but actually they are numerical values in the cells, so i have to type cast them to make anaylsis. as i only need 2nd column elements to manipulate, i took a single dimensional array and made typecasting. HERE IT is throwing EXCEPTION.


    int[] analysis;
    analysis =new integer[row];

    for(int c=0;c<row;c++){

    analysis[c]=Integer.parseInt(x[1][c]);//second column elements //Here i get exception.
    }

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,524
    Blog Entries
    7
    Rep Power
    20

    Default Re: string to integer conversion

    You're mixing up row and colum index values; normally a row runs 'horizontally' and the colums run from left to right; the row index is the first index in a two dimensional array (and the column index is the second index). Draw it on paper while you fix your code; rows are on top of eachother. columns are next to eachother.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. String to Integer Conversion in JSP
    By vinikz in forum New To Java
    Replies: 8
    Last Post: 11-10-2010, 02:45 PM
  2. String to Hex Conversion
    By mocha in forum New To Java
    Replies: 0
    Last Post: 03-17-2010, 08:45 AM
  3. String Conversion....
    By hotice1027 in forum New To Java
    Replies: 8
    Last Post: 11-28-2008, 10:52 PM
  4. string conversion??
    By j2vdk in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 03:35 PM
  5. String to Integer conversion
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-17-2007, 03:59 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
  •