• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

charAt problem....

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep getting an incomparable type error, i guess this is caused by my array?



Any ideas? thanks
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops! Sorry.
reply
    Bookmark Topic Watch Topic
  • New Topic