Stroring into 2d array

string b= acd:tyt:rt;

string a[][]=null;

for(int i=0;i<n;i++){

a[i]=b.split(":");

}

i want to store in 2d array rowwise? any solutions, above code says null ptr exception.>

[392 byte] By [prabhmeeta] at [2007-10-3 8:56:31]
# 1
> i want to store in 2d array rowwise? any solutions,> above code says null ptr exception.No it does not. That code will never compile.
prometheuzza at 2007-7-15 4:06:48 > top of Java-index,Java Essentials,Java Programming...
# 2
so we cant copy into twoD array rowwise?
prabhmeeta at 2007-7-15 4:06:48 > top of Java-index,Java Essentials,Java Programming...
# 3
> so we cant copy into twoD array rowwise?I didn't say that. I meant that the code you posted can never throw any exception because it cannot be compiled.
prometheuzza at 2007-7-15 4:06:48 > top of Java-index,Java Essentials,Java Programming...
# 4

Although it doesn't make a lot of sense, this will compile:int n = 10;

String b= "acd:tyt:rt";

String[][] a= new String[n][];

for(int i = 0; i < n; i++){

a[i] = b.split(":");

}

prometheuzza at 2007-7-15 4:06:48 > top of Java-index,Java Essentials,Java Programming...
# 5

String.split(String) does return an array of Strings, so this code will compile; now what's your problem? This code is different than the OP and shouldn't give you any exceptions. The result of this code, viewed as a grid should be

[["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]

["acd"]["tyt"]["rt"]]

What do you want to happen?

Updownquarka at 2007-7-15 4:06:48 > top of Java-index,Java Essentials,Java Programming...