• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

charAt problem....

 
Stephen Foy
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Keep getting an incomparable type error, i guess this is caused by my array?



Any ideas? thanks
 
kalps ganvir
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
 
Ke rem
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15448
42
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops! Sorry.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic