| Author |
charAt problem....
|
Stephen Foy
Ranch Hand
Joined: Oct 17, 2005
Posts: 143
|
|
Keep getting an incomparable type error, i guess this is caused by my array? Any ideas? thanks
|
Stephen Foy - Microsoft Application Development Consultant
|
 |
kalps ganvir
Greenhorn
Joined: Mar 29, 2006
Posts: 8
|
|
check datatype of blocks array that u hav declared. if it isnt String then declare is as String. try out whether this works
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
You didn't show the declaration of your array blocks[][], but this line: String value = blocks[l][k]; suggests that it's a String[][] array. Note that String.charAt() returns a char. You cannot compare a String to a char using ==, like you're doing here: if(value.charAt(m) == blocks[i][j]) { And this is not going to work: value.charAt(m) = " "; You cannot assign a value to a return value of a method like this, and also String objects are immutable. You'll need to do something like this: blocks[i][j] = value.substring(0, m) + ' ' + value.substring(m + 1);
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Ke rem
Greenhorn
Joined: Apr 12, 2006
Posts: 5
|
|
Yes Jesper is right. and if(value.charAt(m) == blocks[i][j]) can be if((int)value.charAt(m) == (int)blocks[i][j])
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
Originally posted by Ke rem: Yes Jesper is right. and if(value.charAt(m) == blocks[i][j]) can be if((int)value.charAt(m) == (int)blocks[i][j])
That last line is not going to work. blocks[i][j] is a String. You cannot cast a String to an int.
|
 |
Ke rem
Greenhorn
Joined: Apr 12, 2006
Posts: 5
|
|
oops! Sorry.
|
 |
 |
|
|
subject: charAt problem....
|
|
|