Home arrow static arrow Java Programming [Archive] - string 2 dimmension array
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - string 2 dimmension array
This topic has 6 replies on 1 page.

Posts:64
Registered: 12/23/03
string 2 dimmension array  
Aug 5, 2004 1:38 AM



 
i did this :
[CODE]
String[][] unit_table = new String[2][];
while (rs_units.next()) {
unit_table[rs_units.getRow() - 1][0] = rs_units.getString(2);
unit_table[rs_units.getRow() - 1][1] = rs_units.getString(3);
}
[/CODE]
and i get :
Exception: nullwhy is that?
thnaks in advance
peleg
 

Posts:18
Registered: 3/4/03
Re: string 2 dimmension array  
Aug 5, 2004 1:42 AM (reply 1 of 6)



 
I'm not sure if your initialization works. You didn't give the size for both dimensions.
 

Posts:64
Registered: 12/23/03
Re: string 2 dimmension array  
Aug 5, 2004 2:04 AM (reply 2 of 6)



 
well i dint know how many col's i will have in advance
only the number of rows - 2 in this case
 

Posts:2,909
Registered: 13.8.2003
Re: string 2 dimmension array  
Aug 5, 2004 2:10 AM (reply 3 of 6)



 
Well, you still gotta initialize the other arrays too. It doesn't appear by magic.

Object foo[][] = new Object[2][]; for(int i = 0;i < foo.length; i++) {   foo[i] = new Object[getSizeFromSomewhere()];   for(int j = 0;j < foo[i].length; j++)       foo[i][j] = "bar";}

Or use a List if you want dynamic sizing.
 

Posts:64
Registered: 12/23/03
Re: string 2 dimmension array  
Aug 5, 2004 2:58 AM (reply 4 of 6)



 
well i toke your code and did :
int totalRows = rs_units.getFetchSize();
Object unit_table[][] = new Object[2][];
unit_table[0] = new Object[totalRows];
unit_table[1] = new Object[totalRows];
while (rs_units.next()) {
unit_table[0][rs_units.getRow() - 1]=rs_units.getString(2);
unit_table[1][rs_units.getRow() - 1]=rs_units.getString(3);

}

and still it isnt working any idea why?
 

Posts:2,909
Registered: 13.8.2003
Re: string 2 dimmension array  
Aug 5, 2004 3:03 AM (reply 5 of 6)



 
well i toke your code and did :

Don't toke my code please, it's not meant to be smoked.

and still it isnt working any idea why?

What's the exception you're getting, print the beginning of the stack trace (5-10 lines).
 

Posts:64
Registered: 12/23/03
Re: string 2 dimmension array  
Aug 5, 2004 3:08 AM (reply 6 of 6)



 
well i think i have problem with the number of rows that i am trying to recive that gives me 0 and maybe it makes the problem!
i tried to get the rows by this way :
rs_units.rowData.rows.size
but i get the messsage that :
cannot resovle symbol rowData

while i i check the watch and check there the rs_units i see the result withought any problem!
(i worked with intelliJ ide)

any idea why?
and how can i obtain the number of lines in another way?
thnaks in advance
peleg
 
This topic has 6 replies on 1 page.