954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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++;
}

phragix
Newbie Poster
3 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

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).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Thank you very much. I figured it out just now by using substring instead. Thank you again for your reply.

phragix
Newbie Poster
3 posts since Mar 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You