DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   array required, but java.lang.String found (http://www.daniweb.com/forums/thread19414.html)

phragix Mar 1st, 2005 2:02 am
array required, but java.lang.String found
 
I declared mNodes as a String Array and try to assign a value to it with sTemp which is a String as well...but there's an error occurred as: "array required, but java.lang.String found". I don't understand why. I need some suggestion please. Thank you.

String sTemp;
String mNodes[][] = new String [noNodes][6];
for (int iRow = 4; iRow < noNodes + 4; iRow++) {
sTemp = ain.get(iRow).toString();
int mRow = 0;
int mCol = 0;
for (int iCol = 0; iCol < 12; iCol+=2) {
mNodes[mRow][mCol] = sTemp[iCol]; // error occurred here
System.out.println(mNodes[mRow][mCol]);
mCol++;
}

jwenting Mar 1st, 2005 3:27 am
Re: array required, but java.lang.String found
 
A String is not an array of characters in Java (in this Java differs from for example C and Pascal).

The compiler is quite correct and extremely helpful in pointing out that you're trying to use a String as if it were an Array (yes, arrays are also objects).

phragix Mar 1st, 2005 4:12 am
Re: array required, but java.lang.String found
 
Thank you very much. I figured it out just now by using substring instead. Thank you again for your reply.


All times are GMT -4. The time now is 9:51 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC