Results 1 to 4 of 4
Thread: string to integer conversion
- 10-17-2011, 02:18 PM #1
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
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
- 10-17-2011, 03:00 PM #2
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!
- 10-17-2011, 03:19 PM #3
Member
- Join Date
- May 2010
- Posts
- 14
- Rep Power
- 0
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.
}
- 10-17-2011, 03:58 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
String to Integer Conversion in JSP
By vinikz in forum New To JavaReplies: 8Last Post: 11-10-2010, 02:45 PM -
String to Hex Conversion
By mocha in forum New To JavaReplies: 0Last Post: 03-17-2010, 08:45 AM -
String Conversion....
By hotice1027 in forum New To JavaReplies: 8Last Post: 11-28-2008, 10:52 PM -
string conversion??
By j2vdk in forum New To JavaReplies: 13Last Post: 09-19-2008, 03:35 PM -
String to Integer conversion
By eva in forum New To JavaReplies: 2Last Post: 12-17-2007, 03:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks